wheresrhys / fetch-mock-jest

Deprecated - please use https://www.npmjs.com/package/@fetch-mock/jest
http://www.wheresrhys.co.uk/fetch-mock/
MIT License
60 stars 11 forks source link

Keep getting Unmatched GET to "http://example.com" #31

Closed eden-lane closed 3 years ago

eden-lane commented 3 years ago

My code is

import request from 'supertest';
import {app} from '../app';
jest.mock('node-fetch', () => require('fetch-mock-jest').sandbox());
const fetchMock = require('node-fetch');

test('demo created successfully', async () => {
  beforeEach(() => {
    fetchMock.get('*', {
      status: 200
    })

error:

Unmatched GET to https://example.com
wheresrhys commented 3 years ago

Can you set up a repo with a reduced test case I can check out and run myself. Not enough info in the issue to debug

eden-lane commented 3 years ago

Hi! I managed to solve my problem somehow. The worst thing - I still don't understand what was the issue. In my final code I see the line:

fetchMock.enableMocks();

maybe this line solved my problem. I don't see this line in readme and I don't know if it is really important. If it is - I think it would be a good idea to add this to README.md. If it's not important - I'm sorry that I couldn't be of much help.