Skip to content

Commit 049df79

Browse files
chore (test): create test workflow for useLifecycleHelpers
1 parent 0bba1bf commit 049df79

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/test.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
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 './'
210

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+
})

0 commit comments

Comments
 (0)