Jest Add Root And Assertions To Test

/icons/calendar.svg

Last update

Aug 21, 2024

Added Input Root Test Cases to which handle the data disabled case

Example

Before

it('should not be changed when disabled', async () => {
const { input, increment, decrement } = setup({
defaultValue: 0,
disabled: true,
});
await fireEvent.keyDown(input, { key: kbd.ARROW_UP });
expect(input.value).toBe('0');
await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN });
expect(input.value).toBe('0');
await userEvent.click(increment);
expect(input.value).toBe('0');
await userEvent.click(decrement);
expect(input.value).toBe('0');
});

After

it('should not be changed when disabled', async () => {
const { root, input, increment, decrement } = setup({
defaultValue: 0,
disabled: true,
});
expect(root.getAttribute('data-disabled')).toBe('');
expect(input.getAttribute('data-disabled')).toBe('');
await fireEvent.keyDown(input, { key: kbd.ARROW_UP });
expect(input.value).toBe('0');
await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN });
expect(input.value).toBe('0');
await userEvent.click(increment);
expect(input.value).toBe('0');
await userEvent.click(decrement);
expect(input.value).toBe('0');
});

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now