Files
freeCodeCamp/client/src/components/Intro/Intro.test.js
Oliver Eyton-Williams 740370eb60 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.
2021-03-29 16:48:58 -07:00

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: ''
};