ESLint

Install the eslint-plugin-rut package as a dev dependency.

yarn add --dev eslint-plugin-rut

Once installed, add the recommended config to your .eslintrc.js file. By default this will target all test files using ESLint overrides in the format of *.test.(ts|js)x?.

.eslintrc.js
module.exports = {
extends: ['plugin:rut/recommended'],
};

If you prefer to manage the targets yourself, something like the following will suffice.

.eslintrc.js
module.exports = {
overrides: [
{
files: ['*.spec.ts', '*.spec.js'],
plugins: ['rut'],
rules: {
'rut/no-act': 'error',
},
},
],
};

Rules#

consistent-event-type#

Verify and enforce the correct event types are used when mocking or dispatching events.

// Invalid
import { mockEvent, mockSyntheticEvent } from 'rut-dom';
mockEvent('onKeyDown');
mockSyntheticEvent('keydown');
// Valid
import { mockEvent, mockSyntheticEvent } from 'rut-dom';
mockEvent('keydown');
mockSyntheticEvent('onKeyDown');

no-act#

Disallow usage of React's act() within tests. This functionality is provided by Rut and shouldn't be necessary.

// Invalid
import { render } from 'rut-dom';
import { act } from 'react-test-renderer';
import Example from '../src/Example';
const { update } = render(<Example id={1} />);
act(() => {
update({ id: 2 });
});
// Valid
import { render } from 'rut-dom';
import Example from '../src/Example';
const { update } = render(<Example id={1} />);
update({ id: 2 });

no-internals#

Disallow import and usage of Rut's internal APIs. Accessing these directly is a code smell.

// Invalid
import { render } from 'rut-dom';
import debug from 'rut/lib/internals/debug';
import Example from '../src/Example';
const { root } = render(<Example id={1} />);
debug(root);
// Valid
import { render } from 'rut-dom';
import Example from '../src/Example';
const { debug, root } = render(<Example id={1} />);
debug();
// Or
root.debug();

require-render-generics#

Require TypeScript generics for render() and renderAndWait() functions.

// Invalid
import { render } from 'rut-dom';
import Example from '../src/Example';
const { root } = render(<Example id={1} />);
// Valid
import { render } from 'rut-dom';
import Example, { ExampleProps } from '../src/Example';
const { root } = render<ExampleProps>(<Example id={1} />);

Does not apply to host (DOM) elements.