@airglow/plugin-test
v0.8.0
Published
A plugin that stores dispatches for testing
Downloads
46
Readme
Airglow Test Plugin
An Airglow plugin that adds a reducer that tracks all calls that are dispatched throught Airglow.
Usage
Simply enable it:
import testPlugin from '@airglow/plugin-test';
const App = () => (
<Airglow plugins={{
testPlugin()
}}>
<AppContainer />
</Airglow>
);
You can access data using lastDispatch
and dispatchList
:
import React from 'react';
import ReactStore from '@airglow/store-react';
import plugin, { lastDispatch, dispatchList } from '@airglow/plugin-test';
import { renderAirglow } from '../../../../test/util/test.utils';
describe('MyTest', () => {
beforeEach(() => {
tree = renderAirglow(
<div />,
{
plugins: [plugin()],
store: ReactStore
}
);
tree.dispatch({ type: 'testEvent' });
tree.dispatch({ type: 'another' });
});
it('should keep track of all the dispatches', function () {
expect(dispatchList(tree.getState())).toMatchSnapshot();
});
it('should correctly get the last event', function () {
expect(lastDispatch(tree.getState())).toMatchSnapshot();
});
});
That's it!