Answers for "enzyme hasclass example"

0

enzyme hasclass example

// dom.js
import React from 'react'

const DomTest = () => (
  <div>
    <h1 className='header'>
      <span className='sub-header'>Hello World</span>
    </h1>
  </div>
)

export default DomTest

// dom.test.js
test('find element in DomTest Component by class using hasClass', () => {
  expect(wrapper.find('h1').hasClass('header')).toBeTruthy()
  expect(wrapper.find('h1 > span').at(0).hasClass('sub-header')).toBeTruthy()
  expect(wrapper.find('h1').children().find('span').hasClass('sub-header')).toBeTruthy()
  expect(wrapper.find('h1').children().at(0).hasClass('sub-header')).toBeTruthy()
  expect(wrapper.find('h1').childAt(0).hasClass('sub-header')).toBeTruthy()
})
Posted by: Guest on November-21-2020
0

enzyme hasclass example

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');
  });
  
});
Posted by: Guest on November-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language