forked from testing-library/vue-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-props.js
25 lines (20 loc) · 1.07 KB
/
update-props.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import '@testing-library/jest-dom'
import {render} from '@testing-library/vue'
import NumberDisplay from './components/NumberDisplay.vue'
// It'd probably be better if you test the component that's doing the prop
// updating to ensure that the props are being updated correctly.
// That said, if you'd prefer to update the props of a rendered component, this
// function can be used to update props of the rendered component.
test('calling render with the same component but different props does not remount', async () => {
const {getByTestId, updateProps} = render(NumberDisplay, {
props: {number: 1},
})
expect(getByTestId('number-display')).toHaveTextContent('1')
await updateProps({number: 2})
expect(getByTestId('number-display')).toHaveTextContent('2')
await updateProps({number: 3})
expect(getByTestId('number-display')).toHaveTextContent('3')
// Assert that, even after updating props, the component hasn't remounted,
// meaning we are testing the same component instance we rendered initially.
expect(getByTestId('instance-id')).toHaveTextContent('1')
})