Skip to content

Commit

Permalink
completely recreate badSelector between tests so firstRun is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Dec 1, 2023
1 parent 75c2250 commit 50a327f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"prepack": "yarn build",
"bench": "vitest --run bench --mode production",
"test": "node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js run",
"test:watch": "node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js watch",
"test:cov": "vitest run --coverage",
"type-check": "vitest --run typecheck",
"type-check:trace": "vitest --run typecheck && tsc --noEmit -p typescript_test/tsconfig.json --generateTrace trace && npx @typescript/analyze-trace trace && rimraf trace",
Expand Down
10 changes: 6 additions & 4 deletions test/identityFunctionCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { localTest } from './testUtils'
describe('identityFunctionCheck', () => {
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
const identityFunction = vi.fn(<T>(state: T) => state)
const badSelector = createSelector(
let badSelector = createSelector(
[(state: RootState) => state],
identityFunction
)

afterEach(() => {
consoleSpy.mockClear()
identityFunction.mockClear()
badSelector.clearCache()
badSelector.memoizedResultFunc.clearCache()
badSelector = createSelector(
[(state: RootState) => state],
identityFunction
)
})
afterAll(() => {
consoleSpy.mockRestore()
Expand Down Expand Up @@ -42,7 +44,7 @@ describe('identityFunctionCheck', () => {
localTest('includes stack with warning', ({ state }) => {
expect(badSelector(state)).toBe(state)

expect(identityFunction).toHaveBeenCalledTimes(1)
expect(identityFunction).toHaveBeenCalledTimes(2)

expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining(
Expand Down

0 comments on commit 50a327f

Please sign in to comment.