Skip to content

Commit f033274

Browse files
cellogtimdorr
authored andcommitted
migrate bindActionCreators test to typescript (reduxjs#3506)
1 parent c2bca0c commit f033274

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/bindActionCreators.spec.js renamed to test/bindActionCreators.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bindActionCreators, createStore } from '../'
1+
import { bindActionCreators, createStore, ActionCreator } from '..'
22
import { todos } from './helpers/reducers'
33
import * as actionCreators from './helpers/actionCreators'
44

@@ -46,15 +46,17 @@ describe('bindActionCreators', () => {
4646
})
4747

4848
it('skips non-function values in the passed object', () => {
49+
// as this is testing against invalid values, we will cast to unknown and then back to ActionCreator<any>
50+
// in a typescript environment this test is unnecessary, but required in javascript
4951
const boundActionCreators = bindActionCreators(
50-
{
52+
({
5153
...actionCreators,
5254
foo: 42,
5355
bar: 'baz',
5456
wow: undefined,
5557
much: {},
5658
test: null
57-
},
59+
} as unknown) as ActionCreator<any>,
5860
store.dispatch
5961
)
6062
expect(Object.keys(boundActionCreators)).toEqual(
@@ -91,7 +93,10 @@ describe('bindActionCreators', () => {
9193

9294
it('throws for a primitive actionCreator', () => {
9395
expect(() => {
94-
bindActionCreators('string', store.dispatch)
96+
bindActionCreators(
97+
('string' as unknown) as ActionCreator<any>,
98+
store.dispatch
99+
)
95100
}).toThrow(
96101
'bindActionCreators expected an object or a function, instead received string. ' +
97102
'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'

0 commit comments

Comments
 (0)