Socket
Socket
Sign inDemoInstall

jasmine-core

Package Overview
Dependencies
0
Maintainers
3
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jasmine-core

Simple JavaScript testing framework for browsers and node.js


Version published
Weekly downloads
4.4M
decreased by-0.79%
Maintainers
3
Install size
394 kB
Created
Weekly downloads
 

Package description

What is jasmine-core?

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.

What are jasmine-core's main functionalities?

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();
  });
});

Other packages similar to jasmine-core

Readme

Source

Build Status Open Source Helpers FOSSA Status

A JavaScript Testing Framework

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.

Contributing

Please read the contributors' guide.

Installation

For the Jasmine NPM module:
https://github.com/jasmine/jasmine-npm.

For the Jasmine browser runner:
https://github.com/jasmine/jasmine-browser.

For the Jasmine Ruby Gem:
https://github.com/jasmine/jasmine-gem.

To install Jasmine standalone on your local box (where {#.#.#} below is substituted by the release number downloaded):

  • 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-{#.#.#}.zip my-project/jasmine
  • Change directory. - cd my-project/jasmine
  • Unzip the dist. - unzip jasmine-standalone-{#.#.#}.zip

Add the following to your HTML file:

<link rel="shortcut icon" type="image/png" href="lib/jasmine-{#.#.#}/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-{#.#.#}/jasmine.css">

<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-{#.#.#}/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-{#.#.#}/boot.js"></script>

Supported environments

Jasmine tests itself across many browsers (Safari, Chrome, Firefox, Microsoft Edge, and Internet Explorer) as well as nodejs.

EnvironmentSupported versions
Node10, 12, 14, 16
Safari8-14
ChromeEvergreen
FirefoxEvergreen, 68, 78
EdgeEvergreen
Internet Explorer10, 11

For evergreen browsers, each version of Jasmine is tested against the version of the browser that is available to us at the time of release. Other browsers, as well as older & newer versions of some supported browsers, are likely to work. However, Jasmine isn't tested against them and they aren't actively supported.

Support

Maintainers

Maintainers Emeritus

Copyright (c) 2008-2018 Pivotal Labs. This software is licensed under the MIT License.

License

FOSSA Status

Keywords

FAQs

Last updated on 13 Oct 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc