+ ...,
]
`)
})
diff --git a/src/__tests__/new-act.js b/src/__tests__/new-act.js
index 56ce4970..af81e29c 100644
--- a/src/__tests__/new-act.js
+++ b/src/__tests__/new-act.js
@@ -1,4 +1,4 @@
-let asyncAct
+let asyncAct, consoleErrorMock
jest.mock('react-dom/test-utils', () => ({
act: cb => {
@@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
beforeEach(() => {
jest.resetModules()
asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
+ consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
- console.error.mockRestore()
+ consoleErrorMock.mockRestore()
})
test('async act works when it does not exist (older versions of react)', async () => {
@@ -49,7 +49,7 @@ test('async act recovers from errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
- "call console.error",
+ call console.error,
],
]
`)
@@ -67,7 +67,7 @@ test('async act recovers from sync errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
- "call console.error",
+ call console.error,
],
]
`)
diff --git a/src/__tests__/no-act.js b/src/__tests__/no-act.js
index 039a79ae..d739e763 100644
--- a/src/__tests__/no-act.js
+++ b/src/__tests__/no-act.js
@@ -1,14 +1,15 @@
-let act, asyncAct
+let act, asyncAct, React, consoleErrorMock
beforeEach(() => {
jest.resetModules()
- act = require('..').act
+ act = require('../pure').act
asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
+ React = require('react')
+ consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
- console.error.mockRestore()
+ consoleErrorMock.mockRestore()
})
jest.mock('react-dom/test-utils', () => ({}))
@@ -17,7 +18,10 @@ test('act works even when there is no act from test utils', () => {
const callback = jest.fn()
act(callback)
expect(callback).toHaveBeenCalledTimes(1)
- expect(console.error).toHaveBeenCalledTimes(0)
+ expect(console.error).toHaveBeenCalledTimes(
+ // ReactDOM.render is deprecated in React 18
+ React.version.startsWith('18') ? 1 : 0,
+ )
})
test('async act works when it does not exist (older versions of react)', async () => {
@@ -26,7 +30,10 @@ test('async act works when it does not exist (older versions of react)', async (
await Promise.resolve()
await callback()
})
- expect(console.error).toHaveBeenCalledTimes(0)
+ expect(console.error).toHaveBeenCalledTimes(
+ // ReactDOM.render is deprecated in React 18
+ React.version.startsWith('18') ? 2 : 0,
+ )
expect(callback).toHaveBeenCalledTimes(1)
callback.mockClear()
@@ -36,7 +43,10 @@ test('async act works when it does not exist (older versions of react)', async (
await Promise.resolve()
await callback()
})
- expect(console.error).toHaveBeenCalledTimes(0)
+ expect(console.error).toHaveBeenCalledTimes(
+ // ReactDOM.render is deprecated in React 18
+ React.version.startsWith('18') ? 2 : 0,
+ )
expect(callback).toHaveBeenCalledTimes(1)
})
@@ -49,14 +59,16 @@ test('async act recovers from errors', async () => {
} catch (err) {
console.error('call console.error')
}
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
+ expect(console.error).toHaveBeenCalledTimes(
+ // ReactDOM.render is deprecated in React 18
+ React.version.startsWith('18') ? 2 : 1,
+ )
+ expect(
+ console.error.mock.calls[
+ // ReactDOM.render is deprecated in React 18
+ React.version.startsWith('18') ? 1 : 0
+ ][0],
+ ).toMatch('call console.error')
})
test('async act recovers from sync errors', async () => {
@@ -71,7 +83,7 @@ test('async act recovers from sync errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
- "call console.error",
+ call console.error,
],
]
`)
diff --git a/src/__tests__/old-act.js b/src/__tests__/old-act.js
index b3de9377..6081fef8 100644
--- a/src/__tests__/old-act.js
+++ b/src/__tests__/old-act.js
@@ -1,13 +1,13 @@
-let asyncAct
+let asyncAct, consoleErrorMock
beforeEach(() => {
jest.resetModules()
asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
+ consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
- console.error.mockRestore()
+ consoleErrorMock.mockRestore()
})
jest.mock('react-dom/test-utils', () => ({
@@ -32,18 +32,18 @@ test('async act works even when the act is an old one', async () => {
console.error('sigil')
})
expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "sigil",
- ],
- Array [
- "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.",
- ],
- Array [
- "sigil",
- ],
- ]
- `)
+ Array [
+ Array [
+ sigil,
+ ],
+ Array [
+ It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.,
+ ],
+ Array [
+ sigil,
+ ],
+ ]
+ `)
expect(callback).toHaveBeenCalledTimes(1)
// and it doesn't warn you twice
@@ -71,10 +71,10 @@ test('async act recovers from async errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
- "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.",
+ It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.,
],
Array [
- "call console.error",
+ call console.error,
],
]
`)
@@ -92,7 +92,7 @@ test('async act recovers from sync errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
- "call console.error",
+ call console.error,
],
]
`)
@@ -109,11 +109,11 @@ test('async act can handle any sort of console.error', async () => {
Array [
Array [
Object {
- "error": "some error",
+ error: some error,
},
],
Array [
- "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.",
+ It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.,
],
]
`)
diff --git a/src/__tests__/render.js b/src/__tests__/render.js
index fdc1ff4c..fea1a649 100644
--- a/src/__tests__/render.js
+++ b/src/__tests__/render.js
@@ -78,14 +78,14 @@ test('renders options.wrapper around node', () => {
expect(screen.getByTestId('wrapper')).toBeInTheDocument()
expect(container.firstChild).toMatchInlineSnapshot(`
-
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.