Skip to content

Instantly share code, notes, and snippets.

@adrian-afergon
Last active April 11, 2019 20:53
Show Gist options
  • Save adrian-afergon/b636a6f8c3581dda03365b24f10a9120 to your computer and use it in GitHub Desktop.
Save adrian-afergon/b636a6f8c3581dda03365b24f10a9120 to your computer and use it in GitHub Desktop.
Refactor our test after import the exercise builder
import { shallow } from 'enzyme';
import * as React from 'react';
import { ExerciseDetail } from './';
import { createAnExercise } from './ExerciseMockBuilder'
describe('ExerciseDetail', () => {
it('should display the warning when it\'s present in the exercise', () => {
const anExercise: Exercise = createAnExercise({warning: 'a warning message'})
const wrapper = shallow(<ExerciseDetail exercise={anExercise}/>);
const message = wrapper.find('Message');
expect(message.exists()).toBeTruthy();
});
it('should not display the warning when it\'s not set in the exercise', () => {
const anExercise: Exercise = createAnExercise({warning: null})
const wrapper = shallow(<ExerciseDetail exercise={anExercise}/>);
const message = wrapper.find('Message');
expect(message.exists()).toBeFalsy();
});
it('should render a list multiple tags', () => {
const someTags = ['irrelevant tag 1', 'irrelevant tag 2']
const anExercise: Exercise = createAnExercise({tags: someTags})
const wrapper = shallow(<ExerciseDetail exercise={anExercise}/>);
const chips = wrapper.find('Chip');
expect(chips.length).toBe(someTags.length);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment