Difference between revisions of "Jasmine (JavaScript testing framework)"
Karl Jones (Talk | contribs) |
Karl Jones (Talk | contribs) |
||
Line 8: | Line 8: | ||
Jasmine has a number of other features, such as custom matchers, spies, and support for asynchronous specifications. | Jasmine has a number of other features, such as custom matchers, spies, and support for asynchronous specifications. | ||
+ | |||
+ | == Examples == | ||
+ | |||
+ | A simple hello world test looks like the code below, where <code>describe()</code> describes a suite of tests and <code>it()</code> is an individual test specification. | ||
+ | |||
+ | The name "<code>it()</code>" follows the idea of [[behavior-driven development]] and serves as the first word in the test name, which should be a complete sentence. | ||
+ | |||
+ | The code below tests this function: | ||
+ | |||
+ | <pre> | ||
+ | function helloWorld() { | ||
+ | return 'Hello world!'; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | and verifies that its output is indeed the text "Hello world!". | ||
+ | |||
+ | <pre> | ||
+ | describe('Hello world', function() { | ||
+ | it('says hello', function() { | ||
+ | expect(helloWorld()).toEqual('Hello world!'); | ||
+ | }); | ||
+ | }); | ||
+ | </pre> | ||
== Influences == | == Influences == |
Revision as of 10:40, 25 September 2016
Jasmine is an open source unit testing framework for testing JavaScript code.
It uses the behavior-driven development model.
Description
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.
Jasmine has a number of other features, such as custom matchers, spies, and support for asynchronous specifications.
Examples
A simple hello world test looks like the code below, where describe()
describes a suite of tests and it()
is an individual test specification.
The name "it()
" follows the idea of behavior-driven development and serves as the first word in the test name, which should be a complete sentence.
The code below tests this function:
function helloWorld() { return 'Hello world!'; }
and verifies that its output is indeed the text "Hello world!".
describe('Hello world', function() { it('says hello', function() { expect(helloWorld()).toEqual('Hello world!'); }); });
Influences
It is heavily influenced by other unit testing frameworks, such as ScrewUnit, JSSpec, JSpec, and RSpec.
See also
External links
- Official website
- Introduction @ jasmine.github.io
- Jasmine (JavaScript testing framework) @ Wikipedia
- Testing JavaScript Using the Jasmine Framework by Rob Gravelle
- Testing Your JavaScript With Jasmine by Andrew Burgess
- How do I Jasmine: a tutorial by Evan Hahn
YouTube videos
- Unit Testing in JavaScript via Jasmine by Jesse Warden