You've already forked tf2wikipricing
test: fix unit tests for WebExtension build
This commit is contained in:
@@ -57,7 +57,7 @@ describe('prepareExchangeRates', () => {
|
||||
|
||||
const rates = await prepareExchangeRates();
|
||||
expect(rates).toEqual(mockRates);
|
||||
expect(GM_fetch).not.toHaveBeenCalled();
|
||||
expect(GM_fetch as jest.Mock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fetch new rates when they are expired', async () => {
|
||||
@@ -66,17 +66,18 @@ describe('prepareExchangeRates', () => {
|
||||
if (key === storage_exchangerates_next) return new Date(Date.now() - 50000).toISOString();
|
||||
return null;
|
||||
});
|
||||
const mockResponse = {
|
||||
rates: mockRates,
|
||||
time_next_update_utc: new Date(Date.now() + 100000).toISOString()
|
||||
};
|
||||
(GM_fetch as jest.Mock).mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
rates: mockRates,
|
||||
time_next_update_utc: new Date(Date.now() + 100000).toISOString()
|
||||
})
|
||||
json: async () => (mockResponse)
|
||||
});
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockResponse);
|
||||
|
||||
const rates = await prepareExchangeRates();
|
||||
expect(rates).toEqual(mockRates);
|
||||
expect(GM_fetch).toHaveBeenCalled();
|
||||
expect(setStorageValue).toHaveBeenCalledWith(storage_exchangerates, mockRates);
|
||||
});
|
||||
|
||||
@@ -86,6 +87,7 @@ describe('prepareExchangeRates', () => {
|
||||
ok: false,
|
||||
status: 500
|
||||
} as Response);
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => {});
|
||||
|
||||
const rates = await prepareExchangeRates();
|
||||
expect(rates).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user