Skip to content

Instantly share code, notes, and snippets.

@adrian-afergon
Created April 11, 2019 20:42
Show Gist options
  • Save adrian-afergon/a43f715ad232b6253ea5715d20b57337 to your computer and use it in GitHub Desktop.
Save adrian-afergon/a43f715ad232b6253ea5715d20b57337 to your computer and use it in GitHub Desktop.
Create an exercise warning wrapper
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 message = createAnExerciseWarningWrapper(anExercise);
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 message = createAnExerciseWarningWrapper(anExercise);
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);
});
});
const createAnExerciseWarningWrapper = (anExercise: Exercise) => {
const wrapper = shallow(<ExerciseDetail exercise={anExercise}/>);
return wrapper.find('Message');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment