Tester
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, default to a Profile that uses that hook and test it. We will also create a Light profile that allow us to test without the custom hook when needed.
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);
}
},
},
],
profiles: [
{
name: 'Default',
Transport: true,
},
{
name: 'Light',
Transport: false,
},
],
});
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);
});
it('Button triggers API call', async () => {
const tester = await new Tester.Light(Button, { props: { children: 'child string' } }).mount();
expect(tester.text()).toContain('child string');
});
});
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