Closed
Bug 1868561
Opened 2 years ago
Closed 2 years ago
Change our mocking of fetch to fetch-mock-jest
Categories
(Testing :: PerfCompare, task)
Testing
PerfCompare
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: julienw, Assigned: julienw)
References
Details
(Whiteboard: [pcf])
fetch-mock-jest provides a convenient way to mock the fetch API in Jest. It wraps fetch-mock in a way that's more integrated into Jest.
This is used in the profiler this way:
Setup file (not exactly as advertised in their doc, but works well for us):
beforeEach(function () {
// Install fetch and fetch-related objects globally.
// Using the sandbox ensures that parallel tests run properly.
global.fetch = fetchMock.sandbox();
global.Headers = Headers;
global.Request = Request;
global.Response = Response;
});
An example in a test file:
window.fetch.get(
expectedUrl,
makeProfileSerializable(_getSimpleProfile())
);
This can also be asserted:
expect(window.fetch).toHaveBeenCalledWith(
'https://symbolication.services.mozilla.com/symbolicate/v5',
expect.objectContaining({
body: expect.stringMatching(/memoryMap.*firefox/),
})
);
Updated•2 years ago
|
See Also: → https://mozilla-hub.atlassian.net/browse/PCF-360
| Assignee | ||
Updated•2 years ago
|
Assignee: nobody → felash
| Assignee | ||
Comment 1•2 years ago
|
||
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•