es module output
The code published to NPM is commonjs, which can't be run in the browser without transformations.
It would be great if you could provide an output using standard es modules, so that this library can run in the browser directly. As an example, sinon uses rollup to generate an esm bundle (https://github.com/sinonjs/sinon).
Hi @LarsDenBakker, what's your use case? Why are you trying to use fake-fetch in browser env? In case you are using karma you can try browserify preprocessor as described here https://github.com/msn0/fake-fetch#remarks
I'm trying to use fake-fetch in the browser to test my code which runs in the browser.
For example:
<script type="module" src="./my-test.js"></script>
import fakeFetch from 'fake-fetch';
beforeEach(fakeFetch.install);
afterEach(fakeFetch.restore);
it("should fetch what you need", async () => {
fakeFetch.respondWith({"foo": "bar"});
await fetch('/my-service', {headers: new Headers({accept: 'application/json'})});
expect(fakeFetch.getUrl()).toEqual('/my-service');
expect(fakeFetch.getMethod()).toEqual('get');
expect(data._bodyText).toEqual('{"foo":"bar"}');
expect(fakeFetch.getRequestHeaders()).toEqual(new Headers({accept: 'application/json'}));
});
The goal is to not have to run any complex build tooling but to provide a standards-compliant module.