Test Driving Javascript Libraries in the Browser
23 Jun 2014Last 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.
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.