1- import 'react-native'
21import React from 'react'
3- import { act , fireEvent , render } from '@testing-library/react-native'
2+ import {
3+ act ,
4+ cleanup ,
5+ fireEvent ,
6+ render ,
7+ screen ,
8+ } from '@testing-library/react-native'
49import CounterUsesCustomHook from '../src/components/CounterUsesCustomHook'
510import useCounter from '../src/hooks/useCounter'
611import { renderHook } from '@testing-library/react-hooks'
7- import { expect , it , test } from '@jest/globals'
812
9- //testing with the component
13+ afterEach ( cleanup )
14+
1015it ( 'exposes the count and increment/decrement functions' , ( ) => {
11- const { getByText} = render ( < CounterUsesCustomHook /> )
16+ render ( < CounterUsesCustomHook /> )
17+ const { getByText} = screen
1218
1319 const decrement = getByText ( / d e c r e m e n t / i)
1420 const increment = getByText ( / i n c r e m e n t / i)
@@ -22,18 +28,17 @@ it('exposes the count and increment/decrement functions', () => {
2228} )
2329
2430// @ts -ignore
25- function setup ( { initialProps} = { } ) {
31+ const setup = ( { initialProps} = { } ) => {
2632 const result : any = { current : null }
27- function TestComponent ( props : any ) {
33+ const TestComponent = ( props : any ) => {
2834 result . current = useCounter ( props )
2935 return null
3036 }
3137 render ( < TestComponent { ...initialProps } /> )
3238 return result
3339}
3440
35- //testing without component
36- test ( 'exposes the count and increment/decrement functions' , ( ) => {
41+ it ( 'exposes the count and increment/decrement functions- without component' , ( ) => {
3742 const result = setup ( )
3843 expect ( result . current . count ) . toBe ( 0 )
3944 act ( ( ) => result . current . increment ( ) )
@@ -42,12 +47,12 @@ test('exposes the count and increment/decrement functions', () => {
4247 expect ( result . current . count ) . toBe ( 0 )
4348} )
4449
45- test ( 'allows customization of the initial count' , ( ) => {
50+ it ( 'allows customization of the initial count' , ( ) => {
4651 const result = setup ( { initialProps : { initialCount : 3 } } )
4752 expect ( result . current . count ) . toBe ( 3 )
4853} )
4954
50- test ( 'allows customization of the step' , ( ) => {
55+ it ( 'allows customization of the step' , ( ) => {
5156 const result = setup ( { initialProps : { step : 2 } } )
5257 expect ( result . current . count ) . toBe ( 0 )
5358 act ( ( ) => result . current . increment ( ) )
@@ -56,7 +61,7 @@ test('allows customization of the step', () => {
5661 expect ( result . current . count ) . toBe ( 0 )
5762} )
5863
59- test ( 'exposes the count and increment/decrement functions' , ( ) => {
64+ it ( 'exposes the count and increment/decrement functions- hook only ' , ( ) => {
6065 const { result} = renderHook ( useCounter )
6166 expect ( result . current . count ) . toBe ( 0 )
6267 act ( ( ) => result . current . increment ( ) )
0 commit comments