Skip to content

Instantly share code, notes, and snippets.

@diegolameira
Last active August 17, 2020 18:16
Show Gist options
  • Save diegolameira/6e33a104c409a5e432ae3c44f92570c5 to your computer and use it in GitHub Desktop.
Save diegolameira/6e33a104c409a5e432ae3c44f92570c5 to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';
let props;
beforeEach(() => {
props = {
isPrimary: false,
isDanger: false,
isSuccess: false,
};
});
describe('test Button component', () => {
it.each`
propName | propValue | className | result
${'isPrimary'} | ${true} | ${'is-primary'} | ${true}
${'isDanger'} | ${true} | ${'is-danger'} | ${true}
${'isSuccess'} | ${true} | ${'is-success'} | ${true}
`('should have class $className when prop $propName is equal to $propValue', ({propName, propValue, className, result}) => {
props = { ...props, [propName]: propValue };
const enzymeWrapper = shallow(<Button {...props} />);
expect(enzymeWrapper.hasClass(className)).toEqual(result);
});
it.each`
propName | propValue | className | result
${'isPrimary'} | ${false} | ${'is-primary'} | ${false}
${'isDanger'} | ${false} | ${'is-danger'} | ${false}
${'isSuccess'} | ${false} | ${'is-success'} | ${false}
`('should have not class $className when prop $propName is equal to $propValue', ({propName, propValue, className, result}) => {
props = { ...props, [propName]: propValue };
const enzymeWrapper = shallow(<Button {...props} />);
expect(enzymeWrapper.hasClass(className)).toEqual(result);
});
});
@uriannrima
Copy link

God

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment