Difference between revisions of "Jasmine (JavaScript testing framework)"
Karl Jones (Talk | contribs) |
Karl Jones (Talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
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. | ||
+ | |||
+ | == Installing Jasmine standalone on local box == | ||
+ | |||
+ | Download the standalone distribution for your desired release from the [https://github.com/jasmine/jasmine/releases releases page] | ||
+ | |||
+ | Create a Jasmine directory in your project - <code>mkdir my-project/jasmine</code> | ||
+ | |||
+ | Move the dist to your project directory - | ||
+ | |||
+ | <code>mv jasmine/dist/jasmine-standalone-2.0.0.zip my-project/jasmine</code> | ||
+ | |||
+ | Change directory - <code>cd my-project/jasmine</code> | ||
+ | |||
+ | Unzip the dist - <code>unzip jasmine-standalone-2.0.0.zip</code> | ||
+ | |||
+ | Add the following to your HTML file: | ||
+ | |||
+ | <pre> | ||
+ | <link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-2.0.0/jasmine_favicon.png"> | ||
+ | <link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-2.0.0/jasmine.css"> | ||
+ | |||
+ | <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine.js"></script> | ||
+ | <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine-html.js"></script> | ||
+ | <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/boot.js"></script> | ||
+ | </pre> | ||
== Examples == | == Examples == | ||
Line 68: | Line 93: | ||
=== General principles of testing === | === General principles of testing === | ||
− | * [http://www.adequatelygood.com/Writing-Testable-JavaScript.html | + | * [http://www.adequatelygood.com/Writing-Testable-JavaScript.html Writing Testable JavaScript] by Ben Cherry |
− | + | ||
=== Online tools === | === Online tools === |
Latest revision as of 11:20, 25 September 2016
Jasmine is an open source unit testing framework for testing JavaScript code.
It uses the behavior-driven development model.
Contents
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.
Installing Jasmine standalone on local box
Download the standalone distribution for your desired release from the releases page
Create a Jasmine directory in your project - mkdir my-project/jasmine
Move the dist to your project directory -
mv jasmine/dist/jasmine-standalone-2.0.0.zip my-project/jasmine
Change directory - cd my-project/jasmine
Unzip the dist - unzip jasmine-standalone-2.0.0.zip
Add the following to your HTML file:
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-2.0.0/jasmine_favicon.png"> <link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-2.0.0/jasmine.css"> <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine.js"></script> <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine-html.js"></script> <script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/boot.js"></script>
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
- Testing Javascript: get started with Jasmine by Katie Fenn
- JavaScript: Jasmine for unit testing by Adam Cameron
- Jasmine BDD for Javascript by Luis Alfredo Porras Páez
- Pragmatic JavaScript Testing with Jasmine by Jared Carroll
- Test your JavaScript with Jasmine part 1 by Jean Philippe Boily
- Jasmine – JavaScript Unit Testing Tutorial with Examples by Lokesh Gupta
- JavaScript TDD with Jasmine and Karma by Krol Tech
- Testing JavaScript Code with Jasmine Jason Gilmore
- JavaScript Testing with Jasmine by Codeship
- DRYing Up Your JavaScript Jasmine Tests With the Data Provider Pattern by JP
- JavaScript Unit Testing With Jasmine: Part 1 by Joe Zim+
- Introduction to JavaScript BDD Testing With Jasmine Library by Ivan Jovanovic
- Jasmine - Testing JavaScript by Sharon Sudhan
- Jasmine - JavaScript Testing by Yang Zhao
- Getting Started with Node.js and Jasmine by Igor Šarčević
General principles of testing
- Writing Testable JavaScript by Ben Cherry
Online tools
YouTube videos
- Unit Testing in JavaScript via Jasmine by Jesse Warden
- Jasmine: BDD Style JavaScript Testing Hello World by Chris McNabb