11import React from 'react' ;
2- import { shallow } from 'enzyme' ;
2+ import { render , fireEvent } from '@testing-library/react' ;
3+ import '@testing-library/jest-dom' ;
34
45import ConfirmationModal from '.' ;
56
@@ -13,7 +14,7 @@ describe('<ConfirmationModal /> rendering', () => {
1314 } ) ;
1415
1516 it ( 'should render without crashing' , ( ) => {
16- const component = shallow (
17+ const component = render (
1718 < ConfirmationModal
1819 isActive
1920 confirmButtonMessage = "test message"
@@ -25,11 +26,11 @@ describe('<ConfirmationModal /> rendering', () => {
2526 />
2627 ) ;
2728
28- expect ( component ) . toMatchSnapshot ( ) ;
29+ expect ( component . asFragment ( ) ) . toMatchSnapshot ( ) ;
2930 } ) ;
3031
3132 it ( 'should set the active modifier if the isActive prop is passed down' , ( ) => {
32- const component = shallow (
33+ const component = render (
3334 < ConfirmationModal
3435 isActive
3536 confirmButtonMessage = "test message"
@@ -41,11 +42,13 @@ describe('<ConfirmationModal /> rendering', () => {
4142 />
4243 ) ;
4344
44- expect ( component . exists ( 'div.modal.is-active' ) ) . toBeTruthy ( ) ;
45+ expect (
46+ component . container . querySelector ( 'div.modal.is-active' )
47+ ) . toBeTruthy ( ) ;
4548 } ) ;
4649
4750 it ( 'should not set the active modifier if the isActive prop is not passed down' , ( ) => {
48- const component = shallow (
51+ const component = render (
4952 < ConfirmationModal
5053 confirmButtonMessage = "test message"
5154 onConfirmation = { onConfirm }
@@ -56,11 +59,11 @@ describe('<ConfirmationModal /> rendering', () => {
5659 />
5760 ) ;
5861
59- expect ( component . exists ( 'div.modal.is-active' ) ) . toBeFalsy ( ) ;
62+ expect ( component . container . querySelector ( 'div.modal.is-active' ) ) . toBeNull ( ) ;
6063 } ) ;
6164
6265 it ( 'should call onConfirm when the confirmation button is clicked' , ( ) => {
63- const component = shallow (
66+ const component = render (
6467 < ConfirmationModal
6568 isActive
6669 confirmButtonMessage = "confirm test message"
@@ -72,13 +75,12 @@ describe('<ConfirmationModal /> rendering', () => {
7275 />
7376 ) ;
7477
75- component . find ( 'button[children="confirm test message"]' ) . simulate ( 'click' ) ;
76-
78+ fireEvent . click ( component . getByText ( 'confirm test message' ) ) ;
7779 expect ( onConfirm ) . toHaveBeenCalled ( ) ;
7880 } ) ;
7981
8082 it ( 'should call onCancel when the cancel button is clicked' , ( ) => {
81- const component = shallow (
83+ const component = render (
8284 < ConfirmationModal
8385 isActive
8486 confirmButtonMessage = "test message"
@@ -90,13 +92,13 @@ describe('<ConfirmationModal /> rendering', () => {
9092 />
9193 ) ;
9294
93- component . find ( 'button[children=" cancel test message"]' ) . simulate ( 'click' ) ;
95+ fireEvent . click ( component . getByText ( ' cancel test message' ) ) ;
9496
9597 expect ( onCancel ) . toHaveBeenCalled ( ) ;
9698 } ) ;
9799
98100 it ( 'should set the title of the modal' , ( ) => {
99- const component = shallow (
101+ const component = render (
100102 < ConfirmationModal
101103 isActive
102104 confirmButtonMessage = "test message"
@@ -108,11 +110,11 @@ describe('<ConfirmationModal /> rendering', () => {
108110 />
109111 ) ;
110112
111- expect ( component . exists ( 'p[children=" test title"] ') ) . toBeTruthy ( ) ;
113+ expect ( component . getByText ( ' test title') ) . toBeTruthy ( ) ;
112114 } ) ;
113115
114116 it ( 'should set the body of the modal' , ( ) => {
115- const component = shallow (
117+ const component = render (
116118 < ConfirmationModal
117119 isActive
118120 confirmButtonMessage = "test message"
@@ -124,11 +126,11 @@ describe('<ConfirmationModal /> rendering', () => {
124126 />
125127 ) ;
126128
127- expect ( component . exists ( 'section[children=" test body"] ') ) . toBeTruthy ( ) ;
129+ expect ( component . getByText ( ' test body') ) . toBeTruthy ( ) ;
128130 } ) ;
129131
130132 it ( 'should set the confirm button message' , ( ) => {
131- const component = shallow (
133+ const component = render (
132134 < ConfirmationModal
133135 isActive
134136 confirmButtonMessage = "confirm test message"
@@ -140,13 +142,11 @@ describe('<ConfirmationModal /> rendering', () => {
140142 />
141143 ) ;
142144
143- expect (
144- component . exists ( 'button[children="confirm test message"]' )
145- ) . toBeTruthy ( ) ;
145+ expect ( component . getByText ( 'confirm test message' ) ) . toBeTruthy ( ) ;
146146 } ) ;
147147
148148 it ( 'should set the cancel button message' , ( ) => {
149- const component = shallow (
149+ const component = render (
150150 < ConfirmationModal
151151 isActive
152152 confirmButtonMessage = "test message"
@@ -158,8 +158,6 @@ describe('<ConfirmationModal /> rendering', () => {
158158 />
159159 ) ;
160160
161- expect (
162- component . exists ( 'button[children="cancel test message"]' )
163- ) . toBeTruthy ( ) ;
161+ expect ( component . getByText ( 'cancel test message' ) ) . toBeTruthy ( ) ;
164162 } ) ;
165163} ) ;
0 commit comments