0.0.6 • Published 4 years ago

qunit-fixtures v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

qunit-fixtures

CI Build npm version Monthly Downloads from NPM Code Style: prettier

Store test fixtures in files within a designated directory, and assert on those test fixtures in tests.

Installation

yarn add qunit-fixtures --dev

# or

npm install qunit-fixtures --save-dev

Usage

Set up fixture path

Import and run the one-time fixture setup function to load the fixtures for your tests:

import { setupFixtures } from 'qunit-fixtures';

setupFixtures({ fixturePath: './tests/fixtures' });

// ...

:bulb: Tip: It's safe to invoke the setupFixtures function multiple times; the fixtures will be setup only once per test run.

Using the fixture assertion

Fixtures can be asserted on by fixture name. The name corresponds to the path of the fixture within the fixturePath. The following illustrates some examples:

Given the directory with the fixturePath of root/tests/fixtures and the contents below:

├── fixture1.txt
└── sub
    └── fixture2.txt

The fixtures would be read and cached in a data structure like so:

{
  "fixture1": "I am the first fixture",
  "sub/fixture2": "I am the section fixture"
}

And each fixture would be accessible via the key.

The qunit-fixtures library extends QUnit's assert object to include a new function and assertion. The following example illustrates it:

assert.fixture(fixtureName).matches(expectedValue);

Putting it all together

Below is a complete example of using qunit-fixtures in tests.

import { module, test } from 'qunit';
import { setupFixtures } from 'qunit-fixtures';

setupFixtures({ fixturePath: './tests/fixtures' });

module('some-stuff', function() {
  test('doSomeStuff matches the expected result', function(assert) {
    let actualValue = doSomeStuff();

    assert.fixture('some-stuff-result').matches(actualValue);
  });
});

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago