showing results for - "enzyme hasclass example"
Shanna
07 Aug 2018
1// dom.js
2import React from 'react'
3
4const DomTest = () => (
5  <div>
6    <h1 className='header'>
7      <span className='sub-header'>Hello World</span>
8    </h1>
9  </div>
10)
11
12export default DomTest
13
14// dom.test.js
15test('find element in DomTest Component by class using hasClass', () => {
16  expect(wrapper.find('h1').hasClass('header')).toBeTruthy()
17  expect(wrapper.find('h1 > span').at(0).hasClass('sub-header')).toBeTruthy()
18  expect(wrapper.find('h1').children().find('span').hasClass('sub-header')).toBeTruthy()
19  expect(wrapper.find('h1').children().at(0).hasClass('sub-header')).toBeTruthy()
20  expect(wrapper.find('h1').childAt(0).hasClass('sub-header')).toBeTruthy()
21})
Jona
21 Jan 2017
1describe("PageTitle", () => {
2  
3  it("matches snapshot", () => {
4    const tree = renderer.create(<PageTitle pageTitle="Tips" />).toJSON();
5    expect(tree).toMatchSnapshot();
6  });
7
8  it("should display the title passed into the property", () => {
9    const wrapper = shallow(<PageTitle pageTitle="My App"></PageTitle>);
10    expect(wrapper.hasClass('pageTitle')).toEqual(true);
11    expect(wrapper.render().text()).toEqual('My App');
12  });
13  
14});
15