Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response is not defined #136

Closed
vabatta opened this issue Mar 11, 2020 · 2 comments
Closed

Response is not defined #136

vabatta opened this issue Mar 11, 2020 · 2 comments

Comments

@vabatta
Copy link

vabatta commented Mar 11, 2020

Hi,

I am running a Typescript project with ts-jest in place for testing. Running the following code, I get an unhandled promise rejection with the error Response is not defined.

import makeServiceWorkerEnv from 'service-worker-mock';
import makeFetchMock from 'service-worker-mock/fetch';

describe('test handler', () => {
	beforeEach(() => {
		Object.assign(global, makeServiceWorkerEnv(), makeFetchMock());

		jest.resetModules();
	});

	test('return untouched request when there are no redirections', async () => {
		// import the module
		const handler = require('./handler'); // this throws the rejection
		// create a test request
		const stringUrl = 'http://www.example.com/resource.html';
		const req = new Request(stringUrl); // this is created correctly, the mock is active here
		// create a redirections array
		const red: Redirection[] = [];

		const forwardedReq = handler(req, red);
		await expect(forwardedReq).resolves.toBe(req);
	});
});

Any idea of what could be the issue?

@vabatta
Copy link
Author

vabatta commented Mar 12, 2020

Fixed by using jest-fetch-mock for the fetch mocking rather than service-worker-mock/fetch.

@vabatta vabatta closed this as completed Mar 12, 2020
@zba
Copy link

zba commented Apr 18, 2020

I don't think this should be closed, because documentation shows, that it have fetch-mock onboard, use jest-fetch-mock in examples. or fix this.

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

No branches or pull requests

2 participants