Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add test
  • Loading branch information
ben.durrant committed Apr 17, 2023
commit 0c6cd6eb17e87f6495cf6442e6a68f08c5d9e813
23 changes: 22 additions & 1 deletion packages/toolkit/src/tests/createAction.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createAction, getType } from '@reduxjs/toolkit'
import { createAction, getType, isAction } from '@reduxjs/toolkit'

describe('createAction', () => {
it('should create an action', () => {
Expand Down Expand Up @@ -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')
Expand Down