ESLint 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.