Andrew Yurisich a collection of things

Test Driving Javascript Libraries in the Browser

Last week, one of my co-workers showed me a really nice trick you can use if you find yourself needing to validate some snippet that features a javascript library.

Here, I was about to test whether or not I could sort the results of a map call in lodash by going through the typical ceremony of using require in the node interpreter environment.

Testing javascript functionality through node.

Fortunately, said co-worker was working with me when he saw me doing this, and stopped me.

Next time you’re tempted to drop down into an interactive environment to test out an idea like this, instead, just go to that library’s live demo or documentation website. In this case, it was https://lodash.com/docs. Next, open a command-line console in the browser’s developer tools. Using Chrome on a Mac, that would be ⌘ ⌥ j, or ctrl shift j for Windows/Linux. For Firefox, replace j with i.

From there, you’re good to go! Just start using the library, as it’s already been brought into the page via the demo anyhow.

Getting instant access to the Lodash library on the lodash site.