File tree Expand file tree Collapse file tree 1 file changed +40
-6
lines changed Expand file tree Collapse file tree 1 file changed +40
-6
lines changed Original file line number Diff line number Diff line change 1
- import ExampleComponent from './'
1
+ import React , { useState } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import {
4
+ render ,
5
+ fireEvent ,
6
+ cleanup ,
7
+ queryByAttribute
8
+ } from '@testing-library/react'
9
+ import useLifecycleHelpers from './'
2
10
3
- describe ( 'ExampleComponent' , ( ) => {
4
- it ( 'is truthy' , ( ) => {
5
- expect ( ExampleComponent ) . toBeTruthy ( )
6
- } )
7
- } )
11
+ afterEach ( cleanup )
12
+
13
+ const Component = props => {
14
+ const [ componentState , setComponentState ] = useState ( null )
15
+ const [ state , setState ] = useState ( { counter : 0 } )
16
+
17
+ const {
18
+ useComponentDidMount,
19
+ useComponentDidUpdate,
20
+ useComponentWillUnmount,
21
+ useOnDependenciesChange
22
+ } = useLifecycleHelpers ( state , props )
23
+
24
+ return (
25
+ < div id = 'component' >
26
+ < p > { componentState } </ p >
27
+ < button onClick = { ( ) => setState ( { counter : 1 } ) } > Update state</ button >
28
+ </ div >
29
+ )
30
+ }
31
+
32
+ Component . propTypes = {
33
+ data : PropTypes . string
34
+ }
35
+
36
+ function renderComponent ( props ) {
37
+ return render ( < Component { ...props } /> )
38
+ }
39
+
40
+ describe ( 'Test useLifecycleHelpers custom hook' , ( ) => {
41
+ } )
You can’t perform that action at this time.
0 commit comments