Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

TypeError: Cannot read property 'post' of undefined #40

Open
NuckChorris opened this issue May 28, 2021 · 1 comment
Open

TypeError: Cannot read property 'post' of undefined #40

NuckChorris opened this issue May 28, 2021 · 1 comment

Comments

@NuckChorris
Copy link

NuckChorris commented May 28, 2021

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:

├─┬ [email protected]
│ └── [email protected]
├── [email protected] 
└── [email protected] 

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
Copy link

Were you able to resolve this? I'm currently facing the same problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants