Spaces:
Sleeping
Sleeping
Download node_modules/@reduxjs/toolkit/src/tests/actionCreatorInvariantMiddleware.test.ts from Scribbler310/gs-port: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/spaces/Scribbler310/gs-port/resolve/main/node_modules/%40reduxjs/toolkit/src/tests/actionCreatorInvariantMiddleware.test.ts
- Command line
-
hf download hf://spaces/Scribbler310/gs-port/node_modules/@reduxjs/toolkit/src/tests/actionCreatorInvariantMiddleware.test.ts
-
curl -L -o actionCreatorInvariantMiddleware.test.ts https://huggingface.co/spaces/Scribbler310/gs-port/resolve/main/node_modules/%40reduxjs/toolkit/src/tests/actionCreatorInvariantMiddleware.test.ts
1.83 kB
| import type { ActionCreatorInvariantMiddlewareOptions } from '@internal/actionCreatorInvariantMiddleware' | |
| import { getMessage } from '@internal/actionCreatorInvariantMiddleware' | |
| import { createActionCreatorInvariantMiddleware } from '@internal/actionCreatorInvariantMiddleware' | |
| import type { MiddlewareAPI } from '@reduxjs/toolkit' | |
| import { createAction } from '@reduxjs/toolkit' | |
| describe('createActionCreatorInvariantMiddleware', () => { | |
| const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) | |
| afterEach(() => { | |
| consoleSpy.mockClear() | |
| }) | |
| afterAll(() => { | |
| consoleSpy.mockRestore() | |
| }) | |
| const dummyAction = createAction('aSlice/anAction') | |
| it('sends the action through the middleware chain', () => { | |
| const next = vi.fn() | |
| const dispatch = createActionCreatorInvariantMiddleware()( | |
| {} as MiddlewareAPI, | |
| )(next) | |
| dispatch({ type: 'SOME_ACTION' }) | |
| expect(next).toHaveBeenCalledWith({ | |
| type: 'SOME_ACTION', | |
| }) | |
| }) | |
| const makeActionTester = ( | |
| options?: ActionCreatorInvariantMiddlewareOptions, | |
| ) => | |
| createActionCreatorInvariantMiddleware(options)({} as MiddlewareAPI)( | |
| (action) => action, | |
| ) | |
| it('logs a warning to console if an action creator is mistakenly dispatched', () => { | |
| const testAction = makeActionTester() | |
| testAction(dummyAction()) | |
| expect(consoleSpy).not.toHaveBeenCalled() | |
| testAction(dummyAction) | |
| expect(consoleSpy).toHaveBeenLastCalledWith(getMessage(dummyAction.type)) | |
| }) | |
| it('allows passing a custom predicate', () => { | |
| let predicateCalled = false | |
| const testAction = makeActionTester({ | |
| isActionCreator(action): action is Function { | |
| predicateCalled = true | |
| return false | |
| }, | |
| }) | |
| testAction(dummyAction()) | |
| expect(predicateCalled).toBe(true) | |
| }) | |
| }) | |