forked from streamich/react-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: proper definition for isBrowser and isNavigator states.
should fix: streamich#1777 Also introduce jest config for ssr tests (it fails hard now).
- Loading branch information
1 parent
0d3f489
commit b7b0b93
Showing
12 changed files
with
58 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
export const baseJestConfig: Config.InitialOptions = { | ||
'preset': 'ts-jest', | ||
'clearMocks': true, | ||
'coverageDirectory': 'coverage', | ||
'testMatch': [ | ||
'<rootDir>/tests/**/*.test.(ts|tsx)' | ||
], | ||
'setupFiles': [ | ||
'<rootDir>/tests/setupTests.ts' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Config } from '@jest/types'; | ||
import { baseJestConfig } from './jest.config.base'; | ||
|
||
const config: Config.InitialOptions = { | ||
...baseJestConfig, | ||
testEnvironment: 'node', // browser-like | ||
} | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Config } from '@jest/types'; | ||
import { baseJestConfig } from './jest.config.base'; | ||
|
||
const config: Config.InitialOptions = { | ||
...baseJestConfig, | ||
testEnvironment: 'jsdom', // browser-like | ||
} | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
import { isBrowser } from './misc/util'; | ||
|
||
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect; | ||
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect; | ||
|
||
export default useIsomorphicLayoutEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import 'jest-localstorage-mock'; | ||
import { isBrowser } from '../src/misc/util'; | ||
|
||
(window as any).ResizeObserver = class ResizeObserver { | ||
observe() {} | ||
disconnect() {} | ||
}; | ||
if (isBrowser) { | ||
(window as any).ResizeObserver = class ResizeObserver { | ||
observe() { | ||
} | ||
|
||
disconnect() { | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
"lib", | ||
"esm", | ||
"tests", | ||
"stories" | ||
"stories", | ||
"jest.config.ts", | ||
"jest.config.*.ts" | ||
] | ||
} |