1- import React from 'react'
1+ import { render , screen , fireEvent } from '@testing-library/ react'
22import { Provider } from 'react-redux'
3- import { mount } from 'enzyme'
43import configureStore from 'redux-mock-store'
54
65import { actionTypes } from '../../features/counter'
@@ -17,47 +16,43 @@ describe('Counter', () => {
1716 // Add jest mock spy to watch for store.dispatch method. See https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname for more info
1817 jest . spyOn ( store , 'dispatch' )
1918
20- it ( 'renders without crashing.' , ( ) => {
21- const wrapper = mount (
19+ test ( 'renders without crashing.' , ( ) => {
20+ render (
2221 < Provider store = { store } >
2322 < Counter />
2423 </ Provider >
2524 )
2625
27- const countValue = wrapper . find ( 'strong' ) . text ( )
28- expect ( countValue ) . toBe ( '42' )
26+ const countValue = screen . getByText ( '42' )
27+ expect ( countValue ) . toBeInTheDocument ( )
2928 } )
3029
31- it ( 'should be possible to increment counter.' , ( ) => {
32- const wrapper = mount (
30+ test ( 'should be possible to increment counter.' , ( ) => {
31+ render (
3332 < Provider store = { store } >
3433 < Counter />
3534 </ Provider >
3635 )
3736
38- wrapper
39- . find ( 'button' )
40- . filter ( { 'data-qa' : 'increment-counter' } )
41- . simulate ( 'click' )
37+ const incrementButton = screen . getByRole ( 'button' , { name : 'increment' } )
38+ fireEvent . click ( incrementButton )
4239
43- expect ( store . dispatch ) . toBeCalledTimes ( 1 )
40+ expect ( store . dispatch ) . toHaveBeenCalledTimes ( 1 )
4441
45- expect ( store . dispatch ) . toBeCalledWith ( {
42+ expect ( store . dispatch ) . toHaveBeenCalledWith ( {
4643 type : actionTypes . INCREMENT_COUNTER ,
4744 } )
4845 } )
4946
50- it ( 'should be possible to decrement counter.' , ( ) => {
51- const wrapper = mount (
47+ test ( 'should be possible to decrement counter.' , ( ) => {
48+ render (
5249 < Provider store = { store } >
5350 < Counter />
5451 </ Provider >
5552 )
5653
57- wrapper
58- . find ( 'button' )
59- . filter ( { 'data-qa' : 'decrement-counter' } )
60- . simulate ( 'click' )
54+ const decrementButton = screen . getByRole ( 'button' , { name : 'decrement' } )
55+ fireEvent . click ( decrementButton )
6156
6257 expect ( store . dispatch ) . toHaveBeenCalledTimes ( 1 )
6358
0 commit comments