2.6.2 • Published 1 year ago

fusion-test-utils v2.6.2

Weekly downloads
303
License
MIT
Repository
github
Last release
1 year ago

fusion-test-utils

Build status

Provides test utility functions for Fusion.js


yarn add fusion-test-utils

Example

import App from 'fusion-core';
import {getSimulator} from 'fusion-test-utils';

// create simulator
const app = new App();
const simulator = getSimulator(app /*, (optional) test plugin with assertions on dependencies */);

// test renders of your application
const ctx = await simulator.render('/test-url', {
  headers: {
    'x-header': 'value',
  }
});
// do assertions on ctx

// test requests to your application
const ctx = await simulator.request('/test-url', {
  headers: {
    'x-header': 'value',
  }
});
// do assertions on ctx

API

getSimulator(app: FusionApp, testPlugin?: FusionPlugin) => { request, render }

Creates a simulator which exposes functionality to simulate requests and renders through your application. app - instance of a FusionApp testPlugin - optional plugin to make assertions on dependencies

getSimulator(...).request(url: String, options: ?Object) => Promise

Simulates a request through your application. url - path for request options - optional object containing custom settings for the request options.method - the request method, e.g., GET, POST, options.headers - headers to be added to the request options.body - body for the request

getSimulator(...).render(url: String, options: ?Object) => Promise

This is the same as request, but defaults the accept header to text/html which will trigger a render of your application.

test(testName: String, executor: (assert) => {})

A block which executes a test case when using fusion-cli as a test runner. The first argument is the name of the test, and the second argument is a function that executes your test code. The test case will receive a cross-environment assertion helper with all methods defined in the assert module, as well as a .matchSnapshot() method.

Example usage:

import React from 'react';
import {test} from 'fusion-test-utils';
import {shallow} from 'enzyme';

import MyComponent from '../my-component';

test('MyComponent snapshot', assert => {
  const wrapper = shallow(<MyComponent />);
  assert.matchSnapshot(wrapper);
  // And optionally, you can pass your own snapshot name as the second argument
  assert.matchSnapshot(wrapper, 'my snapshot description');
});

test('async functions', async assert => {
  const value = await doSomething();
  assert.equal(true, value, 'something is equal to true');
});

mockFunction()

Returns a mock function which allows you to inspect the mock state via the .mock property. Example usage:

import {mockFunction, test} from '../index';

test('function mocks', assert => {
  const myMock = mockFunction();
  myMock();
  assert.equal(myMock.mock.calls.length, 1);
});
2.6.2

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.5.4

1 year ago

2.4.1

2 years ago

2.4.2

1 year ago

2.5.0

1 year ago

2.5.2

1 year ago

2.5.1

1 year ago

2.5.3

1 year ago

2.4.0

2 years ago

2.3.8

2 years ago

2.3.7

2 years ago

2.3.9

2 years ago

2.3.6

2 years ago

2.3.4

2 years ago

2.3.5

2 years ago

2.3.2

2 years ago

2.3.3

2 years ago

2.3.1

2 years ago

2.3.0

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.4.1

5 years ago

1.4.1-1

5 years ago

1.4.1-0

5 years ago

1.4.0

5 years ago

1.4.0-1

5 years ago

1.4.0-0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.3.0-0

5 years ago

1.2.4

5 years ago

1.2.3

6 years ago

1.2.3-0

6 years ago

1.2.2

6 years ago

1.2.2-0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago