Skip to content

Commit 7859c01

Browse files
committed
tests
1 parent 8472642 commit 7859c01

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/utils/isAction.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)