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.
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/* global expect jest */
|
|
import React from 'react';
|
|
import renderer from 'react-test-renderer';
|
|
import { Provider } from 'react-redux';
|
|
import { createStore } from '../../redux/createStore';
|
|
|
|
import Intro from './';
|
|
|
|
jest.mock('../../analytics');
|
|
|
|
function rendererCreateWithRedux(ui) {
|
|
return renderer.create(<Provider store={createStore()}>{ui}</Provider>);
|
|
}
|
|
|
|
describe('<Intro />', () => {
|
|
it('has no blockquotes when loggedOut', () => {
|
|
const container = rendererCreateWithRedux(<Intro {...loggedOutProps} />)
|
|
.root;
|
|
expect(container.findAllByType('blockquote').length === 0).toBeTruthy();
|
|
expect(container.findAllByType('h1').length === 1).toBeTruthy();
|
|
});
|
|
|
|
it('has a blockquote when loggedIn', () => {
|
|
const container = rendererCreateWithRedux(<Intro {...loggedInProps} />)
|
|
.root;
|
|
expect(container.findAllByType('blockquote').length === 1).toBeTruthy();
|
|
expect(container.findAllByType('h1').length === 1).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
const loggedInProps = {
|
|
complete: true,
|
|
isSignedIn: true,
|
|
name: 'Development User',
|
|
navigate: () => {},
|
|
pending: false,
|
|
slug: '/',
|
|
username: 'DevelopmentUser'
|
|
};
|
|
|
|
const loggedOutProps = {
|
|
complete: true,
|
|
isSignedIn: false,
|
|
name: '',
|
|
navigate: () => {},
|
|
pending: false,
|
|
slug: '/',
|
|
username: ''
|
|
};
|