Skip to content

migrate bindActionCreators test to typescript #3506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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