Tester
![Tester Tester](https://github.com/mighty-justice/tester/raw/HEAD/docs/tester_logo_200w.png?raw=true)
![Coverage Status](https://coveralls.io/repos/github/mighty-justice/tester/badge.svg?branch=master)
Centralize and standardize your tests with easy configuration.
Installation
dependencies
"react": ">=16",
"react-dom": ">=16",
"enzyme": ">=3.8"
npm
npm install --save-dev @mighty-justice/tester
yarn
yarn add --dev @mighty-justice/tester
Quick Start
Tester lets you configure and bootstrap your tests the way you want to. The possibilities are endless, but here's a quick summary to get you started.
In this example, we'll create a Transport hook to mock our API calls and test it.
Configuration
Add this to your jestSetup.js
file.
import enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { TransportMock } from './mocks';
import { ConfigureTester } from '@mighty-justice/tester';
enzyme.configure({ adapter: new Adapter() });
TesterConfig.configure(enzyme, {
hooks: [
{
name: 'Transport',
onInit: (tester) => {
tester.Transport = new TransportMock();
if (tester.opts.registerEndpoints) {
tester.Transport.register(tester.opts.registerEndpoints);
}
},
},
],
});
Usage
Now that our Tester is configured, let's test one of our components.
import Button from './button':
import { Tester } from '@mighty-justice/tester';
describe('Button', () => {
it('Button triggers API call', async () => {
const tester = await new Tester(
Button,
{ props: { callsApiOnClick: true } },
).mount();
expect(tester.Transport.calls.length).toBe(0);
tester.component.simulate('click');
expect(tester.Transport.calls.length).toBe(1);
});
});
Helpers
The most helpful helpers are:
tester.instance
tester.component
tester.html()
tester.text()
tester.wrapper
Here's the full list: Helpers
Contributing
Not availble yet
In the wild
(Not available yet).
Organizations and projects using tester
can list themselves here