at the moment my dfxContent is undefined which is the window.global
declare global {
interface Window {
dfxContent: Record<string, string>
}
}
export interface ReplaceContentModel {
config_key: string
}
export const replaceContent = ({
config_key,
}: ReplaceContentModel): string | Error => {
const message = `No content exists for ${config_key}`
if (window.dfxContent[config_key]) {
return window.dfxContent[config_key]
}
return new Error(message)
}
my tests file
describe('Given a replaceContent util function', () => {
test('window object', () => {
const originalWindow = global.window
originalWindow.dfxContent = { config_key: 'Hi' }
const windowSpy = jest.spyOn(global, 'global', 'get')
windowSpy.mockImplementation(() => ({
...originalWindow,
}))
expect(originalWindow).toBe('Hi')
})
})