Skip to content

Commit 2f7452d

Browse files
committed
Snapshot test to normal toHaveBeenCalledWith assertions
1 parent 579c876 commit 2f7452d

File tree

2 files changed

+28
-47
lines changed

2 files changed

+28
-47
lines changed

src/__tests__/__snapshots__/wait-for-element-to-be-removed.js.snap

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/__tests__/wait-for-element-to-be-removed.js

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ test('it waits for the callback to throw error, a falsy value or empty array and
8484

8585
expect(callback).toHaveBeenCalledTimes(1 + mutationsAndCallbacks.length)
8686
expect(successHandler).toHaveBeenCalledTimes(1)
87-
expect(successHandler.mock.calls[0]).toMatchInlineSnapshot(`
88-
Array [
89-
true,
90-
]
91-
`)
87+
expect(successHandler).toHaveBeenCalledWith(true)
9288
expect(errorHandler).toHaveBeenCalledTimes(0)
9389
})
9490

@@ -121,11 +117,7 @@ test('it waits characterData mutation', async () => {
121117
await promise
122118

123119
expect(successHandler).toHaveBeenCalledTimes(1)
124-
expect(successHandler.mock.calls[0]).toMatchInlineSnapshot(`
125-
Array [
126-
true,
127-
]
128-
`)
120+
expect(successHandler).toHaveBeenCalledWith(true)
129121
expect(errorHandler).toHaveBeenCalledTimes(0)
130122
expect(callback).toHaveBeenCalledTimes(2)
131123
})
@@ -160,11 +152,7 @@ test('it waits for the attributes mutation', async () => {
160152

161153
expect(callback).toHaveBeenCalledTimes(2)
162154
expect(successHandler).toHaveBeenCalledTimes(1)
163-
expect(successHandler.mock.calls[0]).toMatchInlineSnapshot(`
164-
Array [
165-
true,
166-
]
167-
`)
155+
expect(successHandler).toHaveBeenCalledWith(true)
168156
expect(errorHandler).toHaveBeenCalledTimes(0)
169157
})
170158

@@ -199,11 +187,9 @@ test('it throws if timeout is exceeded', async () => {
199187
expect(callback).toHaveBeenCalledTimes(3)
200188
expect(successHandler).toHaveBeenCalledTimes(0)
201189
expect(errorHandler).toHaveBeenCalledTimes(1)
202-
expect(errorHandler.mock.calls[0]).toMatchInlineSnapshot(`
203-
Array [
204-
[Error: Timed out in waitForElementToBeRemoved.],
205-
]
206-
`)
190+
expect(errorHandler).toHaveBeenCalledWith(
191+
new Error('Timed out in waitForElementToBeRemoved.'),
192+
)
207193
})
208194

209195
test('it returns error immediately if there callback returns falsy value, empty array or error before any mutations', async () => {
@@ -258,17 +244,25 @@ test('it returns error immediately if there callback returns falsy value, empty
258244
expect(callbackForFalsy).toHaveBeenCalledTimes(1)
259245
expect(successHandler).toHaveBeenCalledTimes(0)
260246
expect(errorHandler).toHaveBeenCalledTimes(3)
261-
expect(errorHandler.mock.calls[0]).toMatchSnapshot()
262-
expect(errorHandler.mock.calls[1]).toMatchInlineSnapshot(`
263-
Array [
264-
[Error: The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal.],
265-
]
266-
`)
267-
expect(errorHandler.mock.calls[2]).toMatchInlineSnapshot(`
247+
expect(errorHandler.mock.calls[0]).toMatchInlineSnapshot(`
268248
Array [
269-
[Error: The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal.],
249+
[Error: Unable to find an element by: [data-testid="initial-element"]
250+
251+
<div />],
270252
]
271253
`)
254+
expect(errorHandler).toHaveBeenNthCalledWith(
255+
2,
256+
new Error(
257+
'The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal.',
258+
),
259+
)
260+
expect(errorHandler).toHaveBeenNthCalledWith(
261+
3,
262+
new Error(
263+
'The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal.',
264+
),
265+
)
272266
})
273267

274268
test('works if a container is not defined', async () => {
@@ -307,11 +301,7 @@ test('works if a container is not defined', async () => {
307301

308302
expect(callback).toHaveBeenCalledTimes(2)
309303
expect(successHandler).toHaveBeenCalledTimes(1)
310-
expect(successHandler.mock.calls[0]).toMatchInlineSnapshot(`
311-
Array [
312-
true,
313-
]
314-
`)
304+
expect(successHandler).toHaveBeenCalledWith(true)
315305
expect(errorHandler).toHaveBeenCalledTimes(0)
316306

317307
document.getElementsByTagName('html')[0].innerHTML = '' // cleans the document
@@ -335,10 +325,10 @@ test('throws an error if callback is not a function', async () => {
335325
await promise
336326

337327
expect(errorHandler).toHaveBeenCalledTimes(1)
338-
expect(errorHandler.mock.calls[0]).toMatchInlineSnapshot(`
339-
Array [
340-
[Error: waitForElementToBeRemoved requires a function as the first parameter],
341-
]
342-
`)
328+
expect(errorHandler).toHaveBeenCalledWith(
329+
new Error(
330+
'waitForElementToBeRemoved requires a function as the first parameter',
331+
),
332+
)
343333
expect(successHandler).toHaveBeenCalledTimes(0)
344334
})

0 commit comments

Comments
 (0)