I'm trying to access a property that is located under window.sunpietro.config property. When running tests with Jest I'm getting TypeError: Cannot read property 'config' of undefined.
My test code looks like the following:
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import MyModule from '../my.module';
import { myConfigMock } from '../../../../jest.window.mock';
afterEach(cleanup);
beforeEach(() => {
window.sunpietro = { ...myConfigMock };
// window.sunpietro.config = {};
});
describe('MyModule', () => {
test('The module renders correctly', () => {
const { getByTestId } = render(<MyModule />);
getByTestId('my-tabs').toBeDefined();
getByTestId('my-panels').toBeDefined();
});
});
I'm using the latest version of Jest: 24.7.1 and the react-testing-library version: 6.1.2.
How can I mock the window properties so they're accessible by MyModule instance?