G'day:
At work, I've been tasked with getting the team up to speed with TDD whilst we redevelop our website in PHP. I knocked together a presentation on the subject a coupla months ago, but before having a chance to present it, got shifted about in the internal dept structure for a month or so, and it kinda got temporarily shelved. I posted it online: "
TDD presentation". I'm back on the PHP Team now, and need to update said presentation to be more work-requirement-specific, as well as cover unit testing our JavaScript. This has been on our agenda for a coupla years, but was never allowed to get any traction by the decision makers. Decision-making has improved now, so we're all go.
I have
heard about Jasmine, and like the look of it, but have never actually downloaded / installed / ran it. I'm gonna do that today.
(Oh, blogging my work is not something I do... I'm actually off on sick leave at the moment - which I feel slightly guilty about - but I need to get this stuff done, so gonna do it today whilst I am unlikely to get interruptions. I figured as I'm doing it on my own time, I get to blog about it too ;-)
I am writing about this as I do it.
Jasmine
First up: Jasmine. This is
what Wikipedia has to say about Jasmine:
Jasmine is an open source testing framework for JavaScript. It aims to run on any JavaScript-enabled platform, to not intrude on the application nor the IDE, and to have easy-to-read syntax. It is heavily influenced by other unit testing frameworks, such as ScrewUnit, JSSpec, JSpec, and RSpec.
And from its own website:
Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks.
And a code sample from the same page:
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
If you're familiar with
TestBox (and if you're a CFML dev, you bloody should be!), then this will look comfortingly familiar. Indeed that code would run on TestBox.
I know a bit about TestBox, so this is pleasing: I have a head start!
Download & Install
I'm gonna use 2.1.3, which is - at time of writing - the latest version of Jasmine. The download page is here:
jasmine 2.1.3. I've D/Led that and unzipped it into a public directory.
Running
This is too easy... it ships with a file SpecRunner.html, and browsing to that runs the tests. Here are the samples:
Nice!
Example Code
Looking at the code within SpecRunner.html, we see this: