Chapter 7. Using Jasmine with Other Tools
Iâve demonstrated how to run Jasmine using JavaScript in the browser, but you donât have to do it that way. Jasmine works in a variety of other environments and with other tools.
Jasmine and CoffeeScript
CoffeeScript is a language that compiles to JavaScript, and itâs beautiful. It makes coding in JavaScript much easier, and it also makes your Jasmine code look better. Using CoffeeScript with Jasmine is a fairly straightforward process, and your specs will look pretty.
If you donât already use CoffeeScript, Iâd strongly recommend it. Itâs easy to learn if you know JavaScript, and it reduces a lot of the headaches that come with JavaScript. There are some people who donât like CoffeeScript, thoughâitâs up to you whether to use it or not.
If you want to give CoffeeScript a try, you can test it out at CoffeesScript.org, where youâll also find installation instructions and documentation. If you have npm installed, you can install CoffeeScript like so:
sudo npm install -g coffee-script
If you donât have npm or want to use CoffeeScript in a different way, check the CoffeeScript website for more usage instructions.
One of the things that makes Jasmine specs look nice in CoffeeScript is the languageâs optional parentheses. The following two lines are equivalent in CoffeeScript:
alert("Hello world!") alert "Hello world!"
Because Jasmineâs describe
and it
are just functions, you can write nice-looking specs that donât have as ...
Get JavaScript Testing with Jasmine now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.