Skip to content

Commit 9437117

Browse files
committed
chore: added additional tests to ensure pure imports don't add side effects
1 parent e22adbb commit 9437117

9 files changed

+93
-6
lines changed

src/dom/__tests__/autoCleanup.disabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (disabled) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'

src/dom/__tests__/autoCleanup.noAfterEach.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (no afterEach) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
// @ts-expect-error Turning off AfterEach -- ignore Jest LifeCycle Type
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useEffect } from 'react'
2+
3+
import { ReactHooksRenderer } from '../../types/react'
4+
5+
// This verifies that if pure imports are used
6+
// then we DON'T auto-wire up the afterEach for folks
7+
describe('skip auto cleanup (pure) tests', () => {
8+
let cleanupCalled = false
9+
let renderHook: ReactHooksRenderer['renderHook']
10+
11+
beforeAll(() => {
12+
renderHook = (require('../pure') as ReactHooksRenderer).renderHook
13+
})
14+
15+
test('first', () => {
16+
const hookWithCleanup = () => {
17+
useEffect(() => {
18+
return () => {
19+
cleanupCalled = true
20+
}
21+
})
22+
}
23+
renderHook(() => hookWithCleanup())
24+
})
25+
26+
test('second', () => {
27+
expect(cleanupCalled).toBe(false)
28+
})
29+
})

src/native/__tests__/autoCleanup.disabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (disabled) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'

src/native/__tests__/autoCleanup.noAfterEach.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (no afterEach) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
// @ts-expect-error Turning off AfterEach -- ignore Jest LifeCycle Type
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useEffect } from 'react'
2+
3+
import { ReactHooksRenderer } from '../../types/react'
4+
5+
// This verifies that if pure imports are used
6+
// then we DON'T auto-wire up the afterEach for folks
7+
describe('skip auto cleanup (pure) tests', () => {
8+
let cleanupCalled = false
9+
let renderHook: ReactHooksRenderer['renderHook']
10+
11+
beforeAll(() => {
12+
renderHook = (require('../pure') as ReactHooksRenderer).renderHook
13+
})
14+
15+
test('first', () => {
16+
const hookWithCleanup = () => {
17+
useEffect(() => {
18+
return () => {
19+
cleanupCalled = true
20+
}
21+
})
22+
}
23+
renderHook(() => hookWithCleanup())
24+
})
25+
26+
test('second', () => {
27+
expect(cleanupCalled).toBe(false)
28+
})
29+
})

src/server/__tests__/autoCleanup.disabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (disabled) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
process.env.RHTL_SKIP_AUTO_CLEANUP = 'true'

src/server/__tests__/autoCleanup.noAfterEach.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactHooksRenderer } from '../../types/react'
66
// then we DON'T auto-wire up the afterEach for folks
77
describe('skip auto cleanup (no afterEach) tests', () => {
88
let cleanupCalled = false
9-
let renderHook: (arg0: () => void) => void
9+
let renderHook: ReactHooksRenderer['renderHook']
1010

1111
beforeAll(() => {
1212
// @ts-expect-error Turning off AfterEach -- ignore Jest LifeCycle Type
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useEffect } from 'react'
2+
3+
import { ReactHooksRenderer } from '../../types/react'
4+
5+
// This verifies that if pure imports are used
6+
// then we DON'T auto-wire up the afterEach for folks
7+
describe('skip auto cleanup (pure) tests', () => {
8+
let cleanupCalled = false
9+
let renderHook: ReactHooksRenderer['renderHook']
10+
11+
beforeAll(() => {
12+
renderHook = (require('../pure') as ReactHooksRenderer).renderHook
13+
})
14+
15+
test('first', () => {
16+
const hookWithCleanup = () => {
17+
useEffect(() => {
18+
return () => {
19+
cleanupCalled = true
20+
}
21+
})
22+
}
23+
renderHook(() => hookWithCleanup())
24+
})
25+
26+
test('second', () => {
27+
expect(cleanupCalled).toBe(false)
28+
})
29+
})

0 commit comments

Comments
 (0)