Skip to content

Commit 4103966

Browse files
committed
apply act suggestions
1 parent 3a50394 commit 4103966

File tree

3 files changed

+14
-44
lines changed

3 files changed

+14
-44
lines changed

src/testUtils/actSetup.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { vi } from "vitest"
2+
3+
declare global {
4+
// eslint-disable-next-line no-var
5+
var IS_REACT_ACT_ENVIRONMENT: boolean
6+
}
7+
8+
// Let React know that we'll be testing effectful components
9+
global.IS_REACT_ACT_ENVIRONMENT = true
10+
11+
// Mock scheduler to test React features
12+
vi.mock('scheduler', () => require('scheduler/unstable_mock'))

src/testUtils/testUtilsThree.tsx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
1-
import { beforeEach, afterEach } from 'vitest'
21
import { create } from '@react-three/test-renderer'
32
import * as React from 'react'
43

5-
// https://github.com/testing-library/react-testing-library/blob/main/src/act-compat.js
6-
function getGlobalThis() {
7-
/* istanbul ignore else */
8-
if (typeof globalThis !== 'undefined') {
9-
return globalThis
10-
}
11-
/* istanbul ignore next */
12-
if (typeof self !== 'undefined') {
13-
return self
14-
}
15-
/* istanbul ignore next */
16-
if (typeof window !== 'undefined') {
17-
return window
18-
}
19-
/* istanbul ignore next */
20-
if (typeof global !== 'undefined') {
21-
return global
22-
}
23-
/* istanbul ignore next */
24-
throw new Error('unable to locate global object')
25-
}
26-
27-
function setIsReactActEnvironment(isReactActEnvironment: boolean | undefined) {
28-
;(getGlobalThis() as any).IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment
29-
}
30-
31-
function getIsReactActEnvironment() {
32-
return (getGlobalThis() as any).IS_REACT_ACT_ENVIRONMENT
33-
}
34-
35-
let existingIsReactActEnvironment: boolean | undefined
36-
37-
beforeEach(() => {
38-
existingIsReactActEnvironment = getIsReactActEnvironment()
39-
setIsReactActEnvironment(true)
40-
})
41-
42-
afterEach(() => {
43-
setIsReactActEnvironment(existingIsReactActEnvironment)
44-
existingIsReactActEnvironment = undefined
45-
})
46-
474
export async function render(
485
element: React.ReactElement,
496
{

vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config'
33
export default defineConfig({
44
test: {
55
environment: 'happy-dom',
6-
mockReset: true
6+
mockReset: true,
7+
setupFiles: ["src/testUtils/actSetup.ts"],
78
}
89
})

0 commit comments

Comments
 (0)