11import React from 'react' ;
2- import { shallow } from 'enzyme ' ;
2+ import { render , fireEvent } from '@testing-library/react ' ;
33
44import ConfirmationModal from '.' ;
55
@@ -13,7 +13,7 @@ describe('<ConfirmationModal /> rendering', () => {
1313 } ) ;
1414
1515 it ( 'should render without crashing' , ( ) => {
16- const component = shallow (
16+ const component = render (
1717 < ConfirmationModal
1818 isActive
1919 confirmButtonMessage = "test message"
@@ -25,11 +25,11 @@ describe('<ConfirmationModal /> rendering', () => {
2525 />
2626 ) ;
2727
28- expect ( component ) . toMatchSnapshot ( ) ;
28+ expect ( component . asFragment ( ) ) . toMatchSnapshot ( ) ;
2929 } ) ;
3030
3131 it ( 'should set the active modifier if the isActive prop is passed down' , ( ) => {
32- const component = shallow (
32+ const component = render (
3333 < ConfirmationModal
3434 isActive
3535 confirmButtonMessage = "test message"
@@ -41,11 +41,13 @@ describe('<ConfirmationModal /> rendering', () => {
4141 />
4242 ) ;
4343
44- expect ( component . exists ( 'div.modal.is-active' ) ) . toBeTruthy ( ) ;
44+ expect (
45+ component . container . querySelector ( 'div.modal.is-active' )
46+ ) . toBeTruthy ( ) ;
4547 } ) ;
4648
4749 it ( 'should not set the active modifier if the isActive prop is not passed down' , ( ) => {
48- const component = shallow (
50+ const component = render (
4951 < ConfirmationModal
5052 confirmButtonMessage = "test message"
5153 onConfirmation = { onConfirm }
@@ -56,11 +58,11 @@ describe('<ConfirmationModal /> rendering', () => {
5658 />
5759 ) ;
5860
59- expect ( component . exists ( 'div.modal.is-active' ) ) . toBeFalsy ( ) ;
61+ expect ( component . container . querySelector ( 'div.modal.is-active' ) ) . toBeNull ( ) ;
6062 } ) ;
6163
6264 it ( 'should call onConfirm when the confirmation button is clicked' , ( ) => {
63- const component = shallow (
65+ const component = render (
6466 < ConfirmationModal
6567 isActive
6668 confirmButtonMessage = "confirm test message"
@@ -72,13 +74,12 @@ describe('<ConfirmationModal /> rendering', () => {
7274 />
7375 ) ;
7476
75- component . find ( 'button[children="confirm test message"]' ) . simulate ( 'click' ) ;
76-
77+ fireEvent . click ( component . getByText ( 'confirm test message' ) ) ;
7778 expect ( onConfirm ) . toHaveBeenCalled ( ) ;
7879 } ) ;
7980
8081 it ( 'should call onCancel when the cancel button is clicked' , ( ) => {
81- const component = shallow (
82+ const component = render (
8283 < ConfirmationModal
8384 isActive
8485 confirmButtonMessage = "test message"
@@ -90,13 +91,13 @@ describe('<ConfirmationModal /> rendering', () => {
9091 />
9192 ) ;
9293
93- component . find ( 'button[children=" cancel test message"]' ) . simulate ( 'click' ) ;
94+ fireEvent . click ( component . getByText ( ' cancel test message' ) ) ;
9495
9596 expect ( onCancel ) . toHaveBeenCalled ( ) ;
9697 } ) ;
9798
9899 it ( 'should set the title of the modal' , ( ) => {
99- const component = shallow (
100+ const component = render (
100101 < ConfirmationModal
101102 isActive
102103 confirmButtonMessage = "test message"
@@ -108,11 +109,11 @@ describe('<ConfirmationModal /> rendering', () => {
108109 />
109110 ) ;
110111
111- expect ( component . exists ( 'p[children=" test title"] ') ) . toBeTruthy ( ) ;
112+ expect ( component . getByText ( ' test title') ) . toBeTruthy ( ) ;
112113 } ) ;
113114
114115 it ( 'should set the body of the modal' , ( ) => {
115- const component = shallow (
116+ const component = render (
116117 < ConfirmationModal
117118 isActive
118119 confirmButtonMessage = "test message"
@@ -124,11 +125,11 @@ describe('<ConfirmationModal /> rendering', () => {
124125 />
125126 ) ;
126127
127- expect ( component . exists ( 'section[children=" test body"] ') ) . toBeTruthy ( ) ;
128+ expect ( component . getByText ( ' test body') ) . toBeTruthy ( ) ;
128129 } ) ;
129130
130131 it ( 'should set the confirm button message' , ( ) => {
131- const component = shallow (
132+ const component = render (
132133 < ConfirmationModal
133134 isActive
134135 confirmButtonMessage = "confirm test message"
@@ -140,13 +141,11 @@ describe('<ConfirmationModal /> rendering', () => {
140141 />
141142 ) ;
142143
143- expect (
144- component . exists ( 'button[children="confirm test message"]' )
145- ) . toBeTruthy ( ) ;
144+ expect ( component . getByText ( 'confirm test message' ) ) . toBeTruthy ( ) ;
146145 } ) ;
147146
148147 it ( 'should set the cancel button message' , ( ) => {
149- const component = shallow (
148+ const component = render (
150149 < ConfirmationModal
151150 isActive
152151 confirmButtonMessage = "test message"
@@ -158,8 +157,6 @@ describe('<ConfirmationModal /> rendering', () => {
158157 />
159158 ) ;
160159
161- expect (
162- component . exists ( 'button[children="cancel test message"]' )
163- ) . toBeTruthy ( ) ;
160+ expect ( component . getByText ( 'cancel test message' ) ) . toBeTruthy ( ) ;
164161 } ) ;
165162} ) ;
0 commit comments