Created
February 17, 2023 10:00
-
-
Save rjpkuyper/04d49900ab736985636eebb1b5702d69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createUrl, getProducts, Paths } from './get-env-vars' | |
import * as fns from './get-env-vars' | |
describe("GetEnvVars", () => { | |
const MOCKED_PRODCUTS = [{ id: 1 }]; | |
global.fetch = jest.fn(() => Promise.resolve({ | |
json: () => Promise.resolve(MOCKED_PRODCUTS) | |
})); | |
const OLD_ENV = process.env; | |
beforeEach(() => { | |
process.env = { ...OLD_ENV }; | |
delete process.env.NODE_ENV; | |
}); | |
afterEach(() => { | |
process.env = OLD_ENV; | |
}); | |
test('should create a new url', () => { | |
process.env.BASE_URL = 'https://example.com'; | |
expect(createUrl(Paths.PRODUCTS)).toEqual(`${process.env.BASR_URL}/${Paths.PRODUCTS}`); | |
}); | |
test('should get products', async () => { | |
const loggerServiceMock = jest.spyOn(fns, 'createLogger').mockReturnValue({ error: console.error }) | |
expect(await getProducts()).toEqual(MOCKED_PRODCUTS) | |
expect(loggerServiceMock).toBeCalled() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment