Skip to content

Commit

Permalink
fix(core): ✅ fix request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfoucrier committed May 5, 2023
1 parent 167988d commit 79e207b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/__tests__/utils/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it('set correct headers', async () => {
return res.status(200);
});

await request(url, 2e3, requestError, barba.cache);
await request(url, 2e3, requestError, barba.cache, barba.headers);
});

it('throws fetch error', async () => {
Expand All @@ -39,7 +39,7 @@ it('throws fetch error', async () => {
xhrMock.get(url, () => Promise.reject(error));
xhrMock.error(() => {}); // tslint:disable-line:no-empty

await expect(request(url, 2e3, requestError, barba.cache)).rejects.toEqual(error);
await expect(request(url, 2e3, requestError, barba.cache, barba.headers)).rejects.toEqual(error);
expect(requestError).toHaveBeenCalledWith(url, error);
expect(barba.cache.getStatus(url)).toEqual('rejected');
});
Expand All @@ -52,7 +52,7 @@ it('throws result error with 404', async () => {

xhrMock.get(url, (req, res) => res.status(404).reason('Not found'));

await expect(request(url, 2e3, requestError, barba.cache)).rejects.toEqual(error);
await expect(request(url, 2e3, requestError, barba.cache, barba.headers)).rejects.toEqual(error);
expect(requestError).toHaveBeenCalledWith(url, error);
expect(barba.cache.getStatus(url)).toEqual('rejected');
});
Expand All @@ -62,15 +62,15 @@ it('throws timeout error', async () => {

xhrMock.get(url, () => new Promise(() => {})); // tslint:disable-line:no-empty

await expect(request(url, 100, requestError, barba.cache)).rejects.toEqual(error);
await expect(request(url, 100, requestError, barba.cache, barba.headers)).rejects.toEqual(error);
expect(requestError).toHaveBeenCalledWith(url, error);
expect(barba.cache.getStatus(url)).toEqual('rejected');
}, 1000);

it('fetch text content', async () => {
xhrMock.get(url, (req, res) => res.status(200).body('content'));

await expect(request(url, undefined, requestError, barba.cache)).resolves.toBe('content');
await expect(request(url, undefined, requestError, barba.cache, barba.headers)).resolves.toBe('content');
// expect((global as any).window.clearTimeout).toHaveBeenCalledTimes(1);
expect(requestError).not.toHaveBeenCalled();
expect(barba.cache.getStatus(url)).toEqual('fulfilled');
Expand Down

0 comments on commit 79e207b

Please sign in to comment.