Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ben.durrant committed Apr 17, 2023
1 parent 482270e commit 0c6cd6e
Showing 1 changed file with 22 additions and 1 deletion.
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

0 comments on commit 0c6cd6e

Please sign in to comment.