TypeError: Cannot read property 'post' of undefined
Opened this issue · 1 comments
NuckChorris commented
I'm trying to spin up a React project with fetch-mock-jest, and having some strange issues! Specifically I'm seeing that the imported object is undefined!
Versions:
├─┬ fetch-mock-jest@1.5.1
│ └── fetch-mock@9.11.0
├── jest@27.0.1
└── node-fetch@2.6.1
Basically all the errors are:
TypeError: Cannot read property 'post' of undefined
29 |
30 | test('with failed response', async () => {
> 31 | fetchMock.post('https://kitsu.io/api/oauth/token', {
| ^
32 | status: 401,
33 | body: {
34 | error: 'invalid_grant',
at Object.<anonymous> (src/actions/loginWithAssertion.test.ts:31:15)
And an excerpt of the code is:
import fetchMock from 'fetch-mock';
afterEach(() => fetchMock.reset());
jest.mock('app/constants/config');
import { LoginFailed, NetworkError } from 'app/errors';
import loginWithAssertion from './loginWithAssertion';
describe('loginWithAssertion', () => {
test('with successful response', async () => {
fetchMock.post('https://kitsu.io/api/oauth/token', {
status: 200,
...
It's not wrong, either, I dropped into a debugger and it's all undefined 🤷♀️ I don't have any __mocks__
which could be doing this, it's a brand-new project I'm bootstrapping
For further details:
christian98 commented
Were you able to resolve this? I'm currently facing the same problem.