Created
February 6, 2024 17:05
-
-
Save night-fury-rider/b2d2b916caf2f61cae573412ca635e8f to your computer and use it in GitHub Desktop.
React - Jest with Enzyme_Deep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { mount } from 'enzyme'; | |
import UVModal from './UVModal'; | |
let modalShow = true, | |
project = { | |
title: 'Test title', | |
logoUrl: 'Test', | |
desciption: 'Test desciption', | |
duration: 'Test', | |
teamSize: 1, | |
url: 'Test' | |
}, | |
technologies = [{ | |
name: 'Test technologies', | |
logo: 'Test' | |
}], | |
roles= ['Test']; | |
project.technologies = technologies; | |
project.roles = roles; | |
let componentToTest = { | |
title: 'UVModal: ', | |
html: <UVModal show={modalShow} data={project}/> | |
}; | |
let wrapper = mount(componentToTest.html), | |
elementToSearch; | |
it(componentToTest.title + 'renders without crashing', () => { | |
mount(componentToTest.html); | |
}); | |
it(componentToTest.title + 'renders Modal component', () => { | |
expect(wrapper.find(UVModal).length).toEqual(1); | |
}); | |
it(componentToTest.title + 'renders major html elements', () => { | |
// Test weather modal-content element is found and has 3 html children elements. | |
expect(wrapper.find('.modal-content').length).toEqual(1); | |
expect(wrapper.find('.modal-content').children()).toHaveLength(3); | |
// Test weather modal-header element is found and has 2 html children elements. | |
expect(wrapper.find('.modal-header').length).toEqual(1); | |
expect(wrapper.find('.modal-header').children()).toHaveLength(2); | |
// Test weather modal-body element is found and has 1 html child element. | |
expect(wrapper.find('.modal-body').length).toEqual(1); | |
expect(wrapper.find('.modal-body').children()).toHaveLength(1); | |
// Test weather modal-footer element is found and has 1 html child element. | |
expect(wrapper.find('.modal-footer').length).toEqual(1); | |
expect(wrapper.find('.modal-footer').children()).toHaveLength(1); | |
elementToSearch = <p>Lannisters always pay their debt</p>; | |
expect(wrapper.contains(elementToSearch)).toEqual(false); | |
}); | |
it(componentToTest.title + 'renders project data', () => { | |
expect(wrapper.text().indexOf(project.title)).not.toEqual(-1); | |
expect(wrapper.text().indexOf(project.desciption)).not.toEqual(-1); | |
expect(wrapper.text().indexOf(technologies[0].name)).not.toEqual(-1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment