Closed metr1ckzu closed 6 years ago
I'm not used to test containers and I have no idea of what's happening from the logs. It seems to be an error from expect
, but not sure.
Anyway, the way you are creating containers could lead to problems (and perhaps it's the cause of your current problem). Please, take a look on this: https://github.com/diegohaz/arc/issues/131#issuecomment-283296269
@diegohaz I'm kinda new to all this stuff, but i like shorthand syntax in mapDispatchToProps. Maybe it leads to problems but i didn't noticed any one yet. If i will then i would consider to use another approach. But still it's not a case at the moment.
I made changes to mapDispatchToProps
export const mapDispatchToProps = (dispatch) => ({
addTodoRequest: (text) => dispatch(addTodoRequest(text))
})
And changed test:
import {mapDispatchToProps} from '../AddTodoContainer';
it('mapDispatchToProps test', () => {
const text = 'test'
const dispatchSpy = jest.fn()
mapDispatchToProps(dispatchSpy).addTodoRequest(text)
expect(dispatchSpy.mock.calls).toEqual( [ [ { type: 'DEFAULT_ADD_TODO_REQUEST' } ] ])
})
But still encountered an error:
FAIL src/containers/__tests__/AddTodoContainer.test.js
● mapDispatchToProps test
TypeError: (0 , _actions.addTodoRequest) is not a function
at Object.addTodoRequest (src/containers/AddTodoContainer.js:10:219)
at Object.<anonymous> (src/containers/__tests__/AddTodoContainer.test.js:16:60)
Only changing ActionsMock.js made difference:
module.exports = actions.default
And then test passes. Also jest coverage makes warning about actionsMock (before and after small 'fix')
Maybe is there a way to enable default import in tests?
ps. I don't know how mapDispatchToProps can be wrapped like in your comment you've linked. pss. Maybe my repo will help https://github.com/metr1ckzu/todo-arc-redux-ssr
I didn't wrap mapDispatchToProps
, but the component itself.
Hi, i'm not any good in creating issues and probably i'm doing it wrong and wrong place. But i'm trying 3rd day in a row and have no other options. Can't understand what is wrong and help will be appreciated.
I have contianer:
And test for it