refactor: explicit mocking for analytics (#41562)
The previous approach did avoid a fair number of jest.mock calls, but made debugging the tests harder. If you don't know about the mapping it's unclear why the imported module does not behave as normal. By forcing the use of jest.mock it means that the answer to that question is in the test you are working on.
This commit is contained in:
committed by
GitHub
parent
fb40f56876
commit
740370eb60
@@ -1,4 +1,4 @@
|
||||
/* global expect */
|
||||
/* global expect jest */
|
||||
import React from 'react';
|
||||
import ShallowRenderer from 'react-test-renderer/shallow';
|
||||
|
||||
@@ -10,6 +10,8 @@ import envData from '../../../../config/env.json';
|
||||
|
||||
const { apiLocation, clientLocale } = envData;
|
||||
|
||||
jest.mock('../../analytics');
|
||||
|
||||
describe('<UniversalNav />', () => {
|
||||
const UniversalNavProps = {
|
||||
displayMenu: false,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* global expect */
|
||||
/* global expect jest */
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
import { Provider } from 'react-redux';
|
||||
@@ -6,6 +6,8 @@ import { createStore } from '../../redux/createStore';
|
||||
|
||||
import Intro from './';
|
||||
|
||||
jest.mock('../../analytics');
|
||||
|
||||
function rendererCreateWithRedux(ui) {
|
||||
return renderer.create(<Provider store={createStore()}>{ui}</Provider>);
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
/* global expect */
|
||||
/* global expect jest */
|
||||
import React from 'react';
|
||||
import ShallowRenderer from 'react-test-renderer/shallow';
|
||||
|
||||
import IndexPage from '../../pages';
|
||||
import mockChallengeNodes from '../../__mocks__/challenge-nodes';
|
||||
|
||||
jest.mock('../../analytics');
|
||||
|
||||
describe('<Landing />', () => {
|
||||
it('renders when visiting index page and logged out', () => {
|
||||
const shallow = new ShallowRenderer();
|
||||
|
@@ -1,10 +1,12 @@
|
||||
/* global expect */
|
||||
/* global expect jest */
|
||||
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import Profile from './Profile';
|
||||
|
||||
jest.mock('../../analytics');
|
||||
|
||||
const userProps = {
|
||||
user: {
|
||||
profileUI: {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* global expect */
|
||||
/* global expect jest */
|
||||
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
@@ -7,6 +7,8 @@ import { createStore } from '../../redux/createStore';
|
||||
|
||||
import { CertificationSettings } from './Certification';
|
||||
|
||||
jest.mock('../../analytics');
|
||||
|
||||
function renderWithRedux(ui) {
|
||||
return render(<Provider store={createStore()}>{ui}</Provider>);
|
||||
}
|
||||
|
Reference in New Issue
Block a user