Skip to content

Commit

Permalink
migrate bindActionCreators test to typescript (#3506)
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog authored and timdorr committed Aug 16, 2019
1 parent 9ab13e1 commit b67654c
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bindActionCreators, createStore } from '../'
import { bindActionCreators, createStore, ActionCreator } from '..'
import { todos } from './helpers/reducers'
import * as actionCreators from './helpers/actionCreators'

Expand Down Expand Up @@ -46,15 +46,17 @@ describe('bindActionCreators', () => {
})

it('skips non-function values in the passed object', () => {
// as this is testing against invalid values, we will cast to unknown and then back to ActionCreator<any>
// in a typescript environment this test is unnecessary, but required in javascript
const boundActionCreators = bindActionCreators(
{
({
...actionCreators,
foo: 42,
bar: 'baz',
wow: undefined,
much: {},
test: null
},
} as unknown) as ActionCreator<any>,
store.dispatch
)
expect(Object.keys(boundActionCreators)).toEqual(
Expand Down Expand Up @@ -91,7 +93,10 @@ describe('bindActionCreators', () => {

it('throws for a primitive actionCreator', () => {
expect(() => {
bindActionCreators('string', store.dispatch)
bindActionCreators(
('string' as unknown) as ActionCreator<any>,
store.dispatch
)
}).toThrow(
'bindActionCreators expected an object or a function, instead received string. ' +
'Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?'
Expand Down

0 comments on commit b67654c

Please sign in to comment.