Skip to content

Commit e135066

Browse files
committed
Remove export of wrapper from render to reduce surface area
1 parent c536102 commit e135066

File tree

7 files changed

+17
-26
lines changed

7 files changed

+17
-26
lines changed

src/__tests__/components/StopWatch.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export default {
2020
}
2121
},
2222
methods: {
23-
handleClearClick () {
24-
clearInterval(this.timer)
25-
this.lapse = 0
26-
this.running = false
27-
},
2823
handleRunClick () {
2924
if (this.running) {
3025
clearInterval(this.timer)
@@ -36,7 +31,7 @@ export default {
3631
})
3732
}
3833
39-
this.running = !this.running
34+
this.running = !this.running
4035
}
4136
},
4237
beforeDestroy () {

src/__tests__/fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl
99
}),
1010
)
1111

12-
const {wrapper, getByText} = render(Fetch, { props: { url: '/greeting' } })
12+
const {html, getByText} = render(Fetch, { props: { url: '/greeting' } })
1313

1414
// Act
1515
Simulate.click(getByText('Fetch'))
@@ -19,5 +19,5 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl
1919
expect(axiosMock.get).toHaveBeenCalledTimes(1)
2020
expect(axiosMock.get).toHaveBeenCalledWith('/greeting')
2121
expect(getByText('hello there').textContent).toBe('hello there')
22-
expect(wrapper.html()).toMatchSnapshot()
22+
expect(html()).toMatchSnapshot()
2323
})

src/__tests__/form.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@ import Login from './components/Login'
55
test('login form submits', () => {
66
const fakeUser = {username: 'jackiechan', password: 'hiya! 🥋'}
77
const handleSubmit = jest.fn()
8-
const {wrapper, getByLabelText, getByText} = render(
8+
const {updateState, getByLabelText, getByText} = render(
99
Login, { props: { onSubmit: handleSubmit } }
1010
)
1111

1212
const usernameNode = getByLabelText('username')
1313
const passwordNode = getByLabelText('password')
14-
const formNode = wrapper.find('form')
1514
const submitButtonNode = getByText('submit')
1615

1716
// Act - this is waiting on an issue in @vue/test-utils to allow v-model to be updated by
1817
// changes to DOM elements
19-
18+
2019
// Simulate.change(usernameNode, fakeUser.username)
2120
// Simulate.change(passwordNode, fakeUser.password)
22-
wrapper.setData(fakeUser)
21+
updateState(fakeUser)
2322

2423
// NOTE: in jsdom, it's not possible to trigger a form submission
2524
// by clicking on the submit button. This is really unfortunate.
2625
// So the next best thing is to simulate a submit on the form itself
2726
// then ensure that there's a submit button.
28-
Simulate.submit(formNode)
27+
Simulate.click(submitButtonNode)
2928

3029
// Assert
3130
expect(handleSubmit).toHaveBeenCalledTimes(1)

src/__tests__/number-display.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import NumberDisplay from './components/NumberDisplay.vue'
22
import { render } from '../'
33

44
test('calling render with the same component but different props does not remount', () => {
5-
const { queryByTestId, wrapper } = render(NumberDisplay, { props: { number: 1 } })
5+
const { queryByTestId, updateProps } = render(NumberDisplay, { props: { number: 1 } })
66
expect(queryByTestId('number-display').textContent).toBe('1')
77

8-
wrapper.setProps({ number: 2 })
8+
updateProps({ number: 2 })
99
expect(queryByTestId('number-display').textContent).toBe('2')
10-
expect(queryByTestId('instance-id').textContent).toBe('1')
10+
expect(queryByTestId('instance-id').textContent).toBe('1')
1111
})

src/__tests__/stopwatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const wait = time => new Promise(resolve => setTimeout(resolve, time))
77
test('unmounts a component', async () => {
88
jest.spyOn(console, 'error').mockImplementation(() => {})
99

10-
const { unmount, getByText, wrapper } = render(StopWatch)
10+
const { unmount, isUnmounted, getByText, wrapper } = render(StopWatch)
1111
Simulate.click(getByText('start'))
1212

1313
unmount()
14-
expect(wrapper.vm._isDestroyed).toBe(true)
14+
expect(isUnmounted()).toBe(true)
1515

1616
await wait()
1717
expect(console.error).not.toHaveBeenCalled()

src/__tests__/vue-router.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ const routes = [
1313
test('full app rendering/navigating', () => {
1414
const { wrapper, queryByTestId } = render(App, { routes })
1515
// normally I'd use a data-testid, but just wanted to show this is also possible
16-
expect(wrapper.vm.$route.fullPath).toBe('/')
16+
expect(queryByTestId('location-display').textContent).toBe('/')
1717
Simulate.click(queryByTestId('about-link'))
1818
// normally I'd use a data-testid, but just wanted to show this is also possible
1919
expect(queryByTestId('location-display').textContent).toBe('/about')
2020
})
21-
22-
test('landing on a bad page', () => {
23-
const { wrapper, queryByTestId } = render(App, { routes })
24-
wrapper.vm.$router.push({ name: 'some-bad-route' })
25-
expect(queryByTestId('location-display').textContent).toBe('/')
26-
})

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ function render(TestComponent, { props = null, store = null, routes = null } = {
3737
)
3838

3939
return {
40-
wrapper,
4140
unmount: () => wrapper.destroy(),
41+
isUnmounted: () => wrapper.vm._isDestroyed,
42+
html: () => wrapper.html(),
43+
updateProps: _ => wrapper.setProps(_),
44+
updateState: _ => wrapper.setData(_),
4245
...wrapperHelpers
4346
}
4447
}

0 commit comments

Comments
 (0)