Global

Members

(constant) assert :Asserter

Object used for writing assertions. Assertions are created with method calls to this object. Please refer to the comment of each assertion for more information.

Source:
Type:
Examples
assert.isFalse(3 > 4)
assert.that(['hey']).isNotEmpty()

(constant) fail :FailureGenerator

Generates an explicit failure.

Source:
Type:
Example
fail.with('a descriptive message')

(constant) pending :PendingMarker

Marks a test as pending, which is a status that is reported separately, and it's not considered success/failure. It is useful to mark in-progress work and catch the developers attention in the resulting report.

Source:
Type:
Example
pending.dueTo('finish the set-up process')

Methods

after(releaseBlocknon-null) → {void}

Specifies a piece of code that should be executed after each test in a suite. Only one after block is allowed per suite. The most common use of this feature is to ensure you are releasing resources that are used on each test, like files.

Source:
Parameters:
Name Type Description
releaseBlock function

a zero argument function containing the code you want to execute after each test.

Returns:
Type:
void

before(initializationnon-null) → {void}

Specifies a piece of code that should be executed before each test in a suite. Only one before block is allowed per suite. The most common use of this feature is to initialize objects you want to reference in each test.

Source:
Parameters:
Name Type Description
initialization function

a zero argument function containing the code you want to execute before each test.

Returns:
Type:
void
Example
suite('using a before() initializer', () => {
  let number;

  before(() => {
    number = 42;
  });

  test('has the initialized value', () => {
    assert.that(number).isEqualTo(42);
  });
});

suite(namenon-null, suiteBodynon-null) → {TestSuite}

Defines a new test suite. Suites are expected to define tests inside it. There can be more than one suite per file, but it is not possible to nest suites.

Source:
Parameters:
Name Type Description
name string

how you would like to call the suite. Non-empty string.

suiteBody function

the suite definition, written as a zero-argument function.

Returns:
Type:
TestSuite
Example
suite('arithmetic operations', () => {
  test('the sum of two number works', () => {
    assert.areEqual(3 + 4, 7);
  });
});

test(namenon-null, testBodynon-null) → {Test}

Defines a new test. Each test belongs to a test suite and defines assertions in the body.

For info about assertions, take a look at the assert object.

Tests are represented internally as instances of Test.

Source:
Parameters:
Name Type Description
name string

how you would like to call the test. Non-empty string.

testBody function

the test definition, written as a zero-argument function.

Returns:
Type:
Test
Example
test('arithmetic works', () => {
  assert.areEqual(3 + 4, 7);
});