diff --git a/packages/toolkit/src/tests/createAction.test.ts b/packages/toolkit/src/tests/createAction.test.ts index b5e8b67b26..5b481b945c 100644 --- a/packages/toolkit/src/tests/createAction.test.ts +++ b/packages/toolkit/src/tests/createAction.test.ts @@ -1,4 +1,4 @@ -import { createAction, getType } from '@reduxjs/toolkit' +import { createAction, getType, isAction } from '@reduxjs/toolkit' describe('createAction', () => { it('should create an action', () => { @@ -122,6 +122,27 @@ describe('createAction', () => { }) }) +describe('isAction', () => { + it('should only return true for plain objects with a type property', () => { + const actionCreator = createAction('anAction') + class Action { + type = 'totally an action' + } + const testCases: [action: unknown, expected: boolean][] = [ + [{ type: 'an action' }, true], + [{ type: 'more props', extra: true }, true], + [actionCreator(), true], + [actionCreator, false], + [Promise.resolve({ type: 'an action' }), false], + [new Action(), false], + ['a string', false], + ] + for (const [action, expected] of testCases) { + expect(isAction(action)).toBe(expected) + } + }) +}) + describe('getType', () => { it('should return the action type', () => { const actionCreator = createAction('A_TYPE')