Skip to content

Instantly share code, notes, and snippets.

@sagar-gavhane
Created October 4, 2018 13:26
Show Gist options
  • Save sagar-gavhane/7a9172038f236827e13edf22046dd2d6 to your computer and use it in GitHub Desktop.
Save sagar-gavhane/7a9172038f236827e13edf22046dd2d6 to your computer and use it in GitHub Desktop.
Enzyme testing
import React from 'react';
import EnzymeConfig from './../../../enzyme';
import { shallow } from 'enzyme';
import Alert from './Alert';
EnzymeConfig();
describe('Alert component testing', () => {
// 1. alert-primary
it('should be rendered alert-primary', () => {
const wrapper = shallow(<Alert>lorem ipsum dummy text</Alert>);
expect(wrapper.find('.alert-primary').length).toBe(1);
});
// 2. alert-dark
it('should be rendered alert-dark', () => {
const wrapper = shallow(<Alert color="dark">lorem ipsum dummy text</Alert>);
expect(wrapper.find('.alert-dark').length).toBe(1);
});
// 3. alert-warning
it('should be have .alert-warning class', () => {
const wrapper = shallow(<Alert color="warning">Sample alert text!!</Alert>);
expect(wrapper.find('.alert-warning').length).toBe(1);
});
// 4. dimissible button exist
it('should be render dismissible button', () => {
const wrapper = shallow(<Alert dismissible>Sample alert text</Alert>);
expect(wrapper.find('button.close').length).toBe(1);
});
// 5. check text inside alert component
it('should be render input text', () => {
const input = 'Sample alert text';
const wrapper = shallow(<Alert dismissible>{input}</Alert>);
expect(wrapper.text()).toMatch(new RegExp(input));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment