Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
jasmine-core
Advanced tools
The jasmine-core package is the core framework for Jasmine, a behavior-driven development framework for testing JavaScript code. It does not rely on browsers, DOM, or any JavaScript framework, making it suitable for websites, Node.js projects, or anywhere that JavaScript can run.
Writing Test Suites
This feature allows you to group related specs (tests) together. The 'describe' function is for grouping, and 'it' is for individual specs.
describe('A suite is just a function', function() {
var a;
it('and so is a spec', function() {
a = true;
expect(a).toBe(true);
});
});
Matchers
Matchers are used to implement a boolean comparison between the actual value and the expected value. The 'toBe' matcher is one of the simplest matchers.
describe('The 'toBe' matcher compares with ===', function() {
it('and has a positive case', function() {
expect(true).toBe(true);
});
it('and can have a negative case', function() {
expect(false).not.toBe(true);
});
});
Setup and Teardown
Setup and teardown functions like 'beforeEach' and 'afterEach' are used to perform actions before and after each spec in a suite, respectively.
describe('A spec', function() {
beforeEach(function() {
this.value = 0;
});
afterEach(function() {
this.value = null;
});
it('can use the `this` to share state', function() {
expect(this.value).toEqual(0);
this.value += 1;
});
it('prevents test pollution by having an isolated `this` per spec', function() {
expect(this.value).toEqual(0);
});
});
Spies
Spies are used to track calls to functions and all arguments of those calls. They can be used to stub any function and track its usage and calls.
describe('A spy', function() {
var foo, bar = null;
beforeEach(function() {
foo = {
setBar: function(value) {
bar = value;
}
};
spyOn(foo, 'setBar');
foo.setBar(123);
foo.setBar(456, 'another param');
});
it('tracks that the spy was called', function() {
expect(foo.setBar).toHaveBeenCalled();
});
});
Asynchronous Support
Jasmine supports asynchronous testing by using the 'done' function to signal that an async function has completed before moving on to the next spec.
describe('Async spec', function() {
var value;
beforeEach(function(done) {
setTimeout(function() {
value = 0;
done();
}, 1);
});
it('should support async execution of test preparation and expectations', function(done) {
value++;
expect(value).toBeGreaterThan(0);
done();
});
});
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple. It's often compared to Jasmine, with the main difference being that Mocha allows for more flexibility in terms of assertion libraries, mock/stub utilities, and reporting.
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works out of the box for any React project but can be used more broadly. It includes its own assertion library and has a more powerful mocking library compared to Jasmine.
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any JavaScript testing framework. It's often used in conjunction with Mocha and provides a more expressive syntax and additional assertions over Jasmine's built-in matchers.
AVA is a test runner for Node.js with a concise API, detailed error output, and process isolation that lets you develop with confidence. It's different from Jasmine in that it runs tests concurrently, which can be a significant advantage for testing I/O heavy operations.
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, Node.js projects, or anywhere that JavaScript can run.
Documentation & guides live here: http://jasmine.github.io For a quick start guide of Jasmine, see the beginning of http://jasmine.github.io/edge/introduction.html
Upgrading from Jasmine 2.x? Check out the 3.0 release notes for a list of what's new (including breaking changes).
Please read the contributors' guide
For the Jasmine NPM module:
https://github.com/jasmine/jasmine-npm
For the Jasmine Ruby Gem:
https://github.com/jasmine/jasmine-gem
For the Jasmine Python Egg:
https://github.com/jasmine/jasmine-py
For the Jasmine headless browser gulp plugin:
https://github.com/jasmine/gulp-jasmine-browser
To install Jasmine standalone on your local box (where {#.#.#} below is substituted by the release number downloaded):
mkdir my-project/jasmine
mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine
cd my-project/jasmine
unzip jasmine-standalone-{#.#.#}.zip
Add the following to your HTML file:
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-{#.#.#}/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-{#.#.#}/jasmine.css">
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/jasmine-html.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-{#.#.#}/boot.js"></script>
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, PhantomJS, Microsoft Edge, and new Internet Explorer) as well as nodejs. To see the exact version tests are run against look at our .travis.yml
Copyright (c) 2008-2018 Pivotal Labs. This software is licensed under the MIT License.
FAQs
Simple JavaScript testing framework for browsers and node.js
The npm package jasmine-core receives a total of 2,043,404 weekly downloads. As such, jasmine-core popularity was classified as popular.
We found that jasmine-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.