e01.org

Jasmine (software)

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. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

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. ==History== The developers at Pivotal Labs for Jasmine previously developed a similar unit testing framework called JsUnit before active development of Jasmine. 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!'); }); }); Jasmine provides a rich set of built-in matchers. In the above example, toEqual checks the equality between the value returned from the helloWorld() function and the 'Hello world!' string. This is the same as assertions used in other testing frameworks. Jasmine matchers return a Boolean value: true if the expectation is matched (a way to indicate that the test has passed) or false if the expectation does not match. A good practice is to put a single expectation in an individual it() test specification. Other built-in matchers include toBe, toBeTruthy, toBeFalsy, toContain, toBeDefined, toBeUndefined, toBeNull, toBeNaN, toBeGreaterThan, toBeLessThan, toBeCloseTo. The identity matcher toBe checks if two things are the same object. The condition matchers toBeTruthy, toBeFalsy evaluate if something is true or false and toBeDefined, toBeUndefined check if something is defined or undefined. As the name suggests toBeNull checks if something is null and toBeNaN checks if something is not a number (NaN). Precision matcher toBeCloseTo accepts two parameters and checks if a number is close to the first parameter, given a certain amount of decimal precision as indicated by the second parameter. Matcher toContain is used to verify that an element, object or sub-string is contained in an array, list or string. The special built-in matcher toThrow is used to verify that an exception has been thrown. The code below verifies that "Some exception" is thrown. describe('Expect to throw an exception', function() { it('throws some exception', function() { expect( function(){ throw('Some exception'); }).toThrow('Some exception'); }); }); Jasmine has a number of other features, such as custom matchers, spies, and support for asynchronous specifications.

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Jasmine (software)". 1743418937. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1283268904

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·