Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump kcd-scripts to 11.x #921

Merged
merged 4 commits into from Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -50,7 +50,7 @@
"@testing-library/jest-dom": "^5.11.6",
"@types/react-dom": "^17.0.0",
"dotenv-cli": "^4.0.0",
"kcd-scripts": "^7.5.1",
"kcd-scripts": "^11.1.0",
"npm-run-all": "^4.1.5",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand All @@ -68,7 +68,10 @@
"react/no-adjacent-inline-elements": "off",
"import/no-unassigned-import": "off",
"import/named": "off",
"testing-library/no-dom-import": "off"
"testing-library/no-container": "off",
"testing-library/no-dom-import": "off",
"testing-library/no-unnecessary-act": "off",
"testing-library/prefer-user-event": "off"
}
},
"eslintIgnore": [
Expand Down
11 changes: 6 additions & 5 deletions src/__tests__/cleanup.js
Expand Up @@ -54,15 +54,16 @@ describe('fake timers and missing act warnings', () => {
jest.useRealTimers()
})

test('cleanup does not flush immediates', () => {
test('cleanup does not flush microtasks', () => {
const microTaskSpy = jest.fn()
function Test() {
const counter = 1
const [, setDeferredCounter] = React.useState(null)
React.useEffect(() => {
let cancelled = false
setImmediate(() => {
Promise.resolve().then(() => {
microTaskSpy()
Comment on lines -64 to 65
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setImmediate is no longer available in jsdom. Promise.resolve() does the same thing considering the naming microTaskSpy

// eslint-disable-next-line jest/no-if -- false positive
if (!cancelled) {
setDeferredCounter(counter)
}
Expand Down Expand Up @@ -92,12 +93,12 @@ describe('fake timers and missing act warnings', () => {
const [, setDeferredCounter] = React.useState(null)
React.useEffect(() => {
let cancelled = false
setImmediate(() => {
setTimeout(() => {
deferredStateUpdateSpy()
if (!cancelled) {
setDeferredCounter(counter)
}
})
}, 0)

return () => {
cancelled = true
Expand All @@ -108,7 +109,7 @@ describe('fake timers and missing act warnings', () => {
}
render(<Test />)

jest.runAllImmediates()
jest.runAllTimers()
cleanup()

expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/debug.js
Expand Up @@ -43,8 +43,8 @@ test('allows same arguments as prettyDOM', () => {
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"<div>
...",
<div>
...,
]
`)
})
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/new-act.js
Expand Up @@ -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,
],
]
`)
Expand All @@ -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,
],
]
`)
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/no-act.js
Expand Up @@ -2,7 +2,7 @@ let act, asyncAct

beforeEach(() => {
jest.resetModules()
act = require('..').act
act = require('../pure').act
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. would include automatic cleanup i.e. setting up beforeEach and afterEach hooks. This throws now in jest.

asyncAct = require('../act-compat').asyncAct
jest.spyOn(console, 'error').mockImplementation(() => {})
})
Expand Down Expand Up @@ -53,7 +53,7 @@ test('async act recovers from errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"call console.error",
call console.error,
],
]
`)
Expand All @@ -71,7 +71,7 @@ test('async act recovers from sync errors', async () => {
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"call console.error",
call console.error,
],
]
`)
Expand Down
34 changes: 17 additions & 17 deletions src/__tests__/old-act.js
Expand Up @@ -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
Expand Down Expand Up @@ -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,
],
]
`)
Expand All @@ -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,
],
]
`)
Expand All @@ -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.,
],
]
`)
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/render.js
Expand Up @@ -78,14 +78,14 @@ test('renders options.wrapper around node', () => {

expect(screen.getByTestId('wrapper')).toBeInTheDocument()
expect(container.firstChild).toMatchInlineSnapshot(`
<div
data-testid="wrapper"
>
<div
data-testid="inner"
/>
</div>
`)
<div
data-testid=wrapper
>
<div
data-testid=inner
/>
</div>
`)
})

test('flushes useEffect cleanup functions sync on unmount()', () => {
Expand Down
32 changes: 16 additions & 16 deletions types/test.tsx
Expand Up @@ -3,39 +3,39 @@ import {render, fireEvent, screen, waitFor} from '.'
import * as pure from './pure'

export async function testRender() {
const page = render(<button />)
const view = render(<button />)

// single queries
page.getByText('foo')
page.queryByText('foo')
await page.findByText('foo')
view.getByText('foo')
view.queryByText('foo')
await view.findByText('foo')

// multiple queries
page.getAllByText('bar')
page.queryAllByText('bar')
await page.findAllByText('bar')
view.getAllByText('bar')
view.queryAllByText('bar')
await view.findAllByText('bar')

// helpers
const {container, rerender, debug} = page
const {container, rerender, debug} = view
expectType<HTMLElement, typeof container>(container)
return {container, rerender, debug}
}

export async function testPureRender() {
const page = pure.render(<button />)
const view = pure.render(<button />)

// single queries
page.getByText('foo')
page.queryByText('foo')
await page.findByText('foo')
view.getByText('foo')
view.queryByText('foo')
await view.findByText('foo')

// multiple queries
page.getAllByText('bar')
page.queryAllByText('bar')
await page.findAllByText('bar')
view.getAllByText('bar')
view.queryAllByText('bar')
await view.findAllByText('bar')

// helpers
const {container, rerender, debug} = page
const {container, rerender, debug} = view
expectType<HTMLElement, typeof container>(container)
return {container, rerender, debug}
}
Expand Down