diff --git a/src/__tests__/multi-base.js b/src/__tests__/multi-base.js
index c45bcd3..77b2372 100644
--- a/src/__tests__/multi-base.js
+++ b/src/__tests__/multi-base.js
@@ -1,4 +1,3 @@
-import React from 'react'
import {render} from '../'
// these are created once per test suite and reused for each case
@@ -16,10 +15,10 @@ afterAll(() => {
})
test('baseElement isolates trees from one another', () => {
- const {getByText: getByTextInA} = render(
Jekyll
, {
+ const {getByText: getByTextInA} = render(`Jekyll
`, {
baseElement: treeA,
})
- const {getByText: getByTextInB} = render(Hyde
, {
+ const {getByText: getByTextInB} = render(`Hyde
`, {
baseElement: treeB,
})
diff --git a/src/__tests__/new-act.js b/src/__tests__/new-act.js
deleted file mode 100644
index 56ce497..0000000
--- a/src/__tests__/new-act.js
+++ /dev/null
@@ -1,76 +0,0 @@
-let asyncAct
-
-jest.mock('react-dom/test-utils', () => ({
- act: cb => {
- return cb()
- },
-}))
-
-beforeEach(() => {
- jest.resetModules()
- asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
-})
-
-afterEach(() => {
- console.error.mockRestore()
-})
-
-test('async act works when it does not exist (older versions of react)', async () => {
- const callback = jest.fn()
- await asyncAct(async () => {
- await Promise.resolve()
- await callback()
- })
- expect(console.error).toHaveBeenCalledTimes(0)
- expect(callback).toHaveBeenCalledTimes(1)
-
- callback.mockClear()
- console.error.mockClear()
-
- await asyncAct(async () => {
- await Promise.resolve()
- await callback()
- })
- expect(console.error).toHaveBeenCalledTimes(0)
- expect(callback).toHaveBeenCalledTimes(1)
-})
-
-test('async act recovers from errors', async () => {
- try {
- await asyncAct(async () => {
- await null
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-test('async act recovers from sync errors', async () => {
- try {
- await asyncAct(() => {
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-/* eslint no-console:0 */
diff --git a/src/__tests__/no-act.js b/src/__tests__/no-act.js
deleted file mode 100644
index 039a79a..0000000
--- a/src/__tests__/no-act.js
+++ /dev/null
@@ -1,80 +0,0 @@
-let act, asyncAct
-
-beforeEach(() => {
- jest.resetModules()
- act = require('..').act
- asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
-})
-
-afterEach(() => {
- console.error.mockRestore()
-})
-
-jest.mock('react-dom/test-utils', () => ({}))
-
-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)
-})
-
-test('async act works when it does not exist (older versions of react)', async () => {
- const callback = jest.fn()
- await asyncAct(async () => {
- await Promise.resolve()
- await callback()
- })
- expect(console.error).toHaveBeenCalledTimes(0)
- expect(callback).toHaveBeenCalledTimes(1)
-
- callback.mockClear()
- console.error.mockClear()
-
- await asyncAct(async () => {
- await Promise.resolve()
- await callback()
- })
- expect(console.error).toHaveBeenCalledTimes(0)
- expect(callback).toHaveBeenCalledTimes(1)
-})
-
-test('async act recovers from errors', async () => {
- try {
- await asyncAct(async () => {
- await null
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-test('async act recovers from sync errors', async () => {
- try {
- await asyncAct(() => {
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-/* eslint no-console:0 */
diff --git a/src/__tests__/old-act.js b/src/__tests__/old-act.js
deleted file mode 100644
index b3de937..0000000
--- a/src/__tests__/old-act.js
+++ /dev/null
@@ -1,142 +0,0 @@
-let asyncAct
-
-beforeEach(() => {
- jest.resetModules()
- asyncAct = require('../act-compat').asyncAct
- jest.spyOn(console, 'error').mockImplementation(() => {})
-})
-
-afterEach(() => {
- console.error.mockRestore()
-})
-
-jest.mock('react-dom/test-utils', () => ({
- act: cb => {
- cb()
- return {
- then() {
- console.error(
- 'Warning: Do not await the result of calling ReactTestUtils.act(...), it is not a Promise.',
- )
- },
- }
- },
-}))
-
-test('async act works even when the act is an old one', async () => {
- const callback = jest.fn()
- await asyncAct(async () => {
- console.error('sigil')
- await Promise.resolve()
- await callback()
- 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",
- ],
- ]
- `)
- expect(callback).toHaveBeenCalledTimes(1)
-
- // and it doesn't warn you twice
- callback.mockClear()
- console.error.mockClear()
-
- await asyncAct(async () => {
- await Promise.resolve()
- await callback()
- })
- expect(console.error).toHaveBeenCalledTimes(0)
- expect(callback).toHaveBeenCalledTimes(1)
-})
-
-test('async act recovers from async errors', async () => {
- try {
- await asyncAct(async () => {
- await null
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(2)
- 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.",
- ],
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-test('async act recovers from sync errors', async () => {
- try {
- await asyncAct(() => {
- throw new Error('test error')
- })
- } catch (err) {
- console.error('call console.error')
- }
- expect(console.error).toHaveBeenCalledTimes(1)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- "call console.error",
- ],
- ]
- `)
-})
-
-test('async act can handle any sort of console.error', async () => {
- await asyncAct(async () => {
- console.error({error: 'some error'})
- await null
- })
-
- expect(console.error).toHaveBeenCalledTimes(2)
- expect(console.error.mock.calls).toMatchInlineSnapshot(`
- Array [
- Array [
- Object {
- "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.",
- ],
- ]
- `)
-})
-
-test('async act should not show an error when ReactTestUtils.act returns something', async () => {
- jest.resetModules()
- jest.mock('react-dom/test-utils', () => ({
- act: () => {
- return new Promise(resolve => {
- console.error(
- 'Warning: The callback passed to ReactTestUtils.act(...) function must not return anything',
- )
- resolve()
- })
- },
- }))
- asyncAct = require('../act-compat').asyncAct
- await asyncAct(async () => {
- await null
- })
-
- expect(console.error).toHaveBeenCalledTimes(0)
-})
-
-/* eslint no-console:0 */
diff --git a/src/__tests__/rerender.js b/src/__tests__/rerender.js
deleted file mode 100644
index 7cb9156..0000000
--- a/src/__tests__/rerender.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import React from 'react'
-import {render} from '../'
-
-test('rerender will re-render the element', () => {
- const Greeting = props => {props.message}
- const {container, rerender} = render( )
- expect(container.firstChild).toHaveTextContent('hi')
- rerender( )
- expect(container.firstChild).toHaveTextContent('hey')
-})
-
-test('hydrate will not update props until next render', () => {
- const initialInputElement = document.createElement('input')
- const container = document.createElement('div')
- container.appendChild(initialInputElement)
- document.body.appendChild(container)
-
- const firstValue = 'hello'
- initialInputElement.value = firstValue
-
- const {rerender} = render( null} />, {
- container,
- hydrate: true,
- })
-
- expect(initialInputElement.value).toBe(firstValue)
-
- const secondValue = 'goodbye'
- rerender( null} />)
- expect(initialInputElement.value).toBe(secondValue)
-})