We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8472642 commit 7859c01Copy full SHA for 7859c01
test/utils/isAction.spec.ts
@@ -0,0 +1,23 @@
1
+import { isAction } from 'redux'
2
+
3
+describe('isAction', () => {
4
+ it('should only return true for plain objects with a string type property', () => {
5
+ const actionCreator = () => ({ type: 'anAction' })
6
+ class Action {
7
+ type = 'totally an action'
8
+ }
9
+ const testCases: [action: unknown, expected: boolean][] = [
10
+ [{ type: 'an action' }, true],
11
+ [{ type: 'more props', extra: true }, true],
12
+ [{ type: 0 }, false],
13
+ [actionCreator(), true],
14
+ [actionCreator, false],
15
+ [Promise.resolve({ type: 'an action' }), false],
16
+ [new Action(), false],
17
+ ['a string', false]
18
+ ]
19
+ for (const [action, expected] of testCases) {
20
+ expect(isAction(action)).toBe(expected)
21
22
+ })
23
+})
0 commit comments