I am trying to test my async action and I get this error: store.dispatch cannot read property 'then' of undefined
I tried to use the then on the actionTypes (I am sorry, that is an actionCreator but I imported it as actionType), but it goes from undefined to TypeError: actionTypes.fetchGitHubDataAsync(...).then is not a function.
// Response body sample
const mockData = [
{
"name": "javascript",
"display_name": "JavaScript",
"short_description": "JavaScript (JS) is a lightweight interpreted programming language with first-class functions.",
"description": "JavaScript (JS) is a lightweight interpreted or JIT-compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.",
"created_by": "Brendan Eich",
"released": "December 4, 1995",
"created_at": "2016-11-28T18:41:00Z",
"updated_at": "2019-11-06T15:05:24Z",
"featured": true,
"curated": true,
"score": 7954.724
}
]
fetchMock.getOnce('https://api.github.com/search/topics?q=javascript',
{ body: { results: mockData }})
const expectedActions = [
{ type: actionTypes.FETCH_GITHUB_DATA},
]
store.dispatch(actionTypes.fetchGitHubDataAsync())
.then(() => {
expect(store.getActions()).toEqual(expectedActions)
})
})```
Aucun commentaire:
Enregistrer un commentaire