describe("PageTitle", () => { it("matches snapshot", () => { const tree = renderer.create(<PageTitle pageTitle="Tips" />).toJSON(); expect(tree).toMatchSnapshot(); }); it("should display the title passed into the property", () => { const wrapper = shallow(<PageTitle pageTitle="My App"></PageTitle>); expect(wrapper.hasClass('pageTitle')).toEqual(true); expect(wrapper.render().text()).toEqual('My App'); }); });
test('renders properly', t => { const wrapper = shallowWithIntl( <PostListItem {...props} /> ); t.truthy(wrapper.hasClass('single-post')); t.is(wrapper.find('Link').first().prop('children'), post.title); t.regex(wrapper.find('.author-name').first().text(), new RegExp(post.name)); t.is(wrapper.find('.post-desc').first().text(), post.content); });
it('snippet components display special class when active = true', () => { const props = { active: true } let wrapper = shallow(<Snippet {...props} />) expect(wrapper.hasClass('lesson-module-code__code--active')).toEqual(true) wrapper = shallow(<Snippet {...{ active: false }} />) expect(wrapper.hasClass('lesson-module-code__code--active')).toEqual(false) })
test('splash comp', t => { let actual, expect, msg; msg = 'has component class hello'; actual = shallow(Splash).hasClass('splash'); expect = true; t.equal(actual, expect, msg); t.end(); });
test('renders properly', t => { const wrapper = shallow( <App {...props} /> ); // t.is(wrapper.find('Helmet').length, 1); t.is(wrapper.find('Header').length, 1); t.is(wrapper.find('Footer').length, 1); t.is(wrapper.find('Header').prop('toggleAddPost'), wrapper.instance().toggleAddPostSection); t.truthy(wrapper.find('Header + div').hasClass(styles.container)); t.truthy(wrapper.find('Header + div').children(), children); });
it('should delegate classNames & disabled attr to button', () => { const wrapper = shallow( <AsyncButton className="btn btn-default" disabled text="Save" /> ); const $button = wrapper.find('button'); expect($button.hasClass('btn btn-default')).toBe(true); expect($button.prop('disabled')).toBe(true); expect($button.text()).toBe('Save'); });
test('renders properly', t => { const wrapper = shallowWithIntl( <PostCreateWidget {...props} /> ); t.truthy(wrapper.hasClass('form')); t.truthy(wrapper.hasClass('appear')); t.truthy(wrapper.find('h2').first().containsMatchingElement(<FormattedMessage id="createNewPost" />)); t.is(wrapper.find('input').length, 2); t.is(wrapper.find('textarea').length, 1); });
describe("<ControlRow />", () => { it("should match snapshot", () => { const wrapper = shallow(<ControlRow label={testLabel} />) expect(wrapper).toMatchSnapshot() expect(wrapper.html()).toMatchSnapshot() }) it("should render label", () => { const wrapper = shallow(<ControlRow label={testLabel} />) expect(wrapper.find(".label").exists()).toBe(true) expect(wrapper.find(".label").text()).toBe(testLabel) }) it("should render inline when prop is passed", () => { const wrapper = shallow(<ControlRow label={testLabel} inline />) expect(wrapper.find(".row").hasClass("inline")).toBe(true) }) })
it('should set className to root tag, if passed to props', () => { const component = shallow(<Item className="my-class"/>); expect(component.hasClass('my-class')).to.be.true; });
describe('User', () => { it('Should render a user component', () => { const user = shallow(<User user={ sample } />); expect(user.hasClass('user-block')).toBeTruthy(); }); it('Should parse numerical rating', () => { const rating = parseRating(10); const expectedRating = '★☆☆☆☆'; expect(rating['__html']).toEqual(expectedRating); }); });
it('Class of rendered table', () => { const header = shallow(<Header />); expect(header.find('div').first().hasClass('App-header')); });
describe('<Humburger />', () => { it('should render an Humburger', () => { const wrapper = shallow(<Humburger />); expect(wrapper).to.exist(); }); it('should contains a button with "navbar-toggle" class', () => { const wrapper = shallow(<Humburger />); const button = wrapper.find('button'); expect(button.hasClass('navbar-toggle')).to.equal(true); }); it('should contains "<span className="icon-bar"></span>"', () => { const wrapper = shallow(<Humburger />); expect(wrapper.contains(<span className="icon-bar" />)).to.equal(true); }); });
describe('<Column />', function() { it('should render correctly', function() { const component = renderer.create(<Column/>); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); it('should have the correct class name', function () { const component = shallow(<Column className="col-md-6" />); expect(component.find('div').hasClass('col-md-6')).toBe(true); }) })
it('codeHeader components display special class when active = true', () => { const props = { active: true } let wrapper = shallow(<CodeHeader {...props} />) expect(wrapper.hasClass('lesson-module-code__trigger--active')).toEqual(true) wrapper = shallow(<CodeHeader {...{ active: false }} />) expect(wrapper.hasClass('lesson-module-code__trigger--active')).toEqual(false) })
describe('AvatarStack', () => { it('should render with an "avatar-stack" class', () => { const wrapper = shallow(<AvatarStack users={[]} />); expect(wrapper.hasClass('avatar-stack')).toBeTruthy(); }); it('should render X number of Avatar components for users', () => { const users = [ { id: 1, avatar_url: 'http://' }, { id: 2, avatar_url: 'http://' }, ]; const wrapper = shallow(<AvatarStack users={users} />); expect(wrapper.find(Avatar).length).toBe(users.length); }); });