diff --git a/src/user-event/__mocks__/utils.js b/src/user-event/__mocks__/utils.js index 450cafc2..4f23e45d 100644 --- a/src/user-event/__mocks__/utils.js +++ b/src/user-event/__mocks__/utils.js @@ -1,3 +1,5 @@ +// this helps us track what the state is before and after an event is fired +// this is needed for determining the snapshot values const {getElementDisplayName} = require('../__tests__/helpers/utils') const actual = jest.requireActual('../utils') diff --git a/src/user-event/__tests__/clear.js b/src/user-event/__tests__/clear.js index 40abe33f..5ad3c413 100644 --- a/src/user-event/__tests__/clear.js +++ b/src/user-event/__tests__/clear.js @@ -2,10 +2,10 @@ import * as userEvent from '..' import {setup} from './helpers/utils' test('clears text', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.clear(element) expect(element).toHaveValue('') - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value=""] input[value="hello"] - focus @@ -26,19 +26,19 @@ test('works with textarea', async () => { }) test('does not clear text on disabled inputs', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.clear(element) expect(element).toHaveValue('hello') - expect(getEventCalls()).toMatchInlineSnapshot( + expect(getEventSnapshot()).toMatchInlineSnapshot( `No events were fired on: input[value="hello"]`, ) }) test('does not clear text on readonly inputs', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.clear(element) expect(element).toHaveValue('hello') - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value="hello"] input[value="hello"] - focus diff --git a/src/user-event/__tests__/click.js b/src/user-event/__tests__/click.js index fe7e1746..3538194c 100644 --- a/src/user-event/__tests__/click.js +++ b/src/user-event/__tests__/click.js @@ -2,9 +2,9 @@ import * as userEvent from '..' import {setup, addEventListener, addListeners} from './helpers/utils' test('click in input', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.click(element) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[value=""] input[value=""] - mouseover: Left (0) @@ -18,9 +18,9 @@ test('click in input', async () => { }) test('click in textarea', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.click(element) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: textarea[value=""] textarea[value=""] - mouseover: Left (0) @@ -34,10 +34,10 @@ test('click in textarea', async () => { }) test('should fire the correct events for ', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') expect(element).not.toBeChecked() await userEvent.click(element) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[checked=true] input[checked=false] - mouseover: Left (0) @@ -55,11 +55,13 @@ test('should fire the correct events for ', async () => { }) test('should fire the correct events for ', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup( + '', + ) await userEvent.click(element) expect(element).toBeDisabled() // no event calls is expected here: - expect(getEventCalls()).toMatchInlineSnapshot( + expect(getEventSnapshot()).toMatchInlineSnapshot( `No events were fired on: input[checked=false]`, ) expect(element).toBeDisabled() @@ -67,10 +69,10 @@ test('should fire the correct events for ', asyn }) test('should fire the correct events for ', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') expect(element).not.toBeChecked() await userEvent.click(element) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[checked=true] input[checked=false] - mouseover: Left (0) @@ -90,11 +92,11 @@ test('should fire the correct events for ', async () => { }) test('should fire the correct events for ', async () => { - const {element, getEventCalls} = setup('') + const {element, getEventSnapshot} = setup('') await userEvent.click(element) expect(element).toBeDisabled() // no event calls is expected here: - expect(getEventCalls()).toMatchInlineSnapshot( + expect(getEventSnapshot()).toMatchInlineSnapshot( `No events were fired on: input[checked=false]`, ) expect(element).toBeDisabled() @@ -103,9 +105,9 @@ test('should fire the correct events for ', async ( }) test('should fire the correct events for
', async () => { - const {element, getEventCalls} = setup('
') + const {element, getEventSnapshot} = setup('
') await userEvent.click(element) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: div div - mouseover: Left (0) @@ -141,12 +143,12 @@ test('should blur the previous element', async () => { const a = element.children[0] const b = element.children[1] - const {getEventCalls, clearEventCalls} = addListeners(a) + const {getEventSnapshot, clearEventCalls} = addListeners(a) await userEvent.click(a) clearEventCalls() await userEvent.click(b) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[name="a"][value=""] input[name="a"][value=""] - mouseover: Left (0) @@ -169,12 +171,12 @@ test('should not blur the previous element when mousedown prevents default', asy addEventListener(b, 'mousedown', e => e.preventDefault()) - const {getEventCalls, clearEventCalls} = addListeners(a) + const {getEventSnapshot, clearEventCalls} = addListeners(a) await userEvent.click(a) clearEventCalls() await userEvent.click(b) - expect(getEventCalls()).toMatchInlineSnapshot(` + expect(getEventSnapshot()).toMatchInlineSnapshot(` Events fired on: input[name="a"][value=""] input[name="a"][value=""] - mouseover: Left (0) @@ -268,31 +270,31 @@ test('clicking a label checks the radio', async () => { }) test('submits a form when clicking on a `) + const {element, eventWasFired} = setup(`
`) await userEvent.click(element.children[0]) - expect(getEventCalls()).toContain('submit') + expect(eventWasFired('submit')).toBe(true) }) test('does not submit a form when clicking on a `) await userEvent.click(element.children[0]) - expect(getEventCalls()).not.toContain('submit') + expect(getEventSnapshot()).not.toContain('submit') }) test('does not fire blur on current element if is the same as previous', async () => { - const {element, getEventCalls, clearEventCalls} = setup('