ArticleslgStudy

computer science

Jasmine (software)

Jasmine (software) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Jasmine (software) rather than just read about it. In short: 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.

Jasmine (software) — main illustration
Jasmine (software) — illustration

Key takeaways

  • Jasmine (software) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Jasmine (software) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Jasmine (software) from memory before moving on to harder problems.

Reference excerpt

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.

Features Supports asynchronous testing. Makes use of 'spies' for implementing test doubles. Supports testing of front-end code through a front-end extension of Jasmine called Jasmine-jQuery.

Usage Jasmine aims to be easy to read. 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. Usage follows syntax similar to that of RSpec. The code below tests this function

and verifies that its output is indeed the text "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.

Jasmine has a number of other features, such as custom matchers, spies, and support for asynchronous specifications.

Jasmine test runners Jasmine comes with an inbuilt test runner. Jasmine tests can run browser tests by including a simple SpecRunner.html file or by using it as a command line test runner supported for various languages like Nodejs, Python, Ruby, or (old way) by using Karma, a simple JavaScript test runner tool.

Comparison between Jasmine and Mocha Mocha is another popular Javascript testing framework. The comparison between Jasmine and Mocha is given in the table below.

Benefits The aim of Jasmine is to be browser, framework, platform and language independent. Besides behavior-driven development, Jasmine also supports test driven development.

See also List of JavaScript libraries List of unit testing frameworks Mocha (JavaScript framework) QUnit JavaScript framework JavaScript library

References

External links Official website Jasmine on GitHub

Worked examples

Example 1 — a first encounter with Jasmine (software)

Start with the simplest possible case. Write down what Jasmine (software) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Jasmine (software) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Jasmine (software) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Jasmine (software)

In research
Jasmine (software) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Jasmine (software) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Jasmine (software) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free software programmed in JavaScript, JavaScript programming tools, Software using the MIT license, so understanding it makes those chapters shorter.
In everyday life
Look for Jasmine (software) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Jasmine (software)” →

How to study Jasmine (software) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Jasmine (software) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Jasmine (software) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Jasmine (software) in simple terms?

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.

Why does Jasmine (software) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Jasmine (software)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Jasmine (software).

Tags

  • Free software programmed in JavaScript
  • JavaScript programming tools
  • Software using the MIT license
  • Unit testing frameworks

Keep exploring