-
Notifications
You must be signed in to change notification settings - Fork 26k
/
concurrent.js
67 lines (60 loc) · 1.89 KB
/
concurrent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint-env jest */
import webdriver from 'next-webdriver'
import { check, renderViaHTTP } from 'next-test-utils'
export default (context, _render) => {
async function withBrowser(path, cb) {
let browser
try {
browser = await webdriver(context.appPort, path)
await cb(browser)
} finally {
if (browser) {
await browser.close()
}
}
}
it('throws if useFlushEffects is used more than once', async () => {
await renderViaHTTP(context.appPort, '/use-flush-effect/multiple-calls')
expect(context.stderr).toContain(
'Error: The `useFlushEffects` hook cannot be used more than once.'
)
})
it('throws if useFlushEffects is called on the client', async () => {
await withBrowser('/use-flush-effect/client', async (browser) => {
await check(
() => browser.waitForElementByCss('#error').text(),
/useFlushEffects can not be called on the client/
)
})
})
it('flushes styled-jsx styles as the page renders', async () => {
const html = await renderViaHTTP(
context.appPort,
'/use-flush-effect/styled-jsx'
)
const stylesOccurrence = html.match(/color:(\s)*blue/g) || []
expect(stylesOccurrence.length).toBe(1)
await withBrowser('/use-flush-effect/styled-jsx', async (browser) => {
await check(
() => browser.waitForElementByCss('#__jsx-900f996af369fc74').text(),
/blue/
)
await check(
() => browser.waitForElementByCss('#__jsx-8b0811664c4e575e').text(),
/red/
)
})
})
it('flushes custom effects', async () => {
await withBrowser('/use-flush-effect/custom', async (browser) => {
await check(
() => browser.waitForElementByCss('#custom-flush-effect-1').text(),
/foo/
)
await check(
() => browser.waitForElementByCss('#custom-flush-effect-2').text(),
/bar/
)
})
})
}