Skip to content

[PoC] VTL@next: Update to Vue 3.0 and Vue Test Utils 2.0 #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c41507f
Bump Vue and VTU
afontcu Apr 27, 2020
a1b91ed
Identify TODOs
afontcu Apr 27, 2020
76c6624
Allow propsData (mark as breaking change)
afontcu Apr 27, 2020
ecfc251
Remove removed method
afontcu Apr 27, 2020
e9d5f95
Fix fire-event tests
afontcu Apr 27, 2020
9d1663e
Add basic TS config (is this needed?)
afontcu Apr 27, 2020
3659de3
Add link to related issue
afontcu Apr 27, 2020
e2ae9c8
Fix form.vue (not sure how this is related to Vue3?
afontcu Apr 27, 2020
75b58a2
Remove unrelated test – we need to add a cleaner way to test unmount
afontcu Apr 27, 2020
2175993
Fix inline snapshot
afontcu Apr 27, 2020
23730bc
Fix stubs test
afontcu Apr 27, 2020
ee56d98
Rename updateProps to setProps to align with VTU
afontcu Apr 27, 2020
8ab20b3
Bump deps
afontcu May 20, 2020
b2c597c
Silence third-party tests
afontcu May 20, 2020
fa3b7bf
Remove outdated comment
afontcu May 22, 2020
a1fca69
Comment out tests that relies on vue2 initialization and setting up
afontcu May 22, 2020
7af298a
Comment out vue-apollo (relies on vue2)
afontcu Jun 7, 2020
650ff5a
Comment out test that rely on vue2
afontcu Jun 8, 2020
09adb61
Comment out potential deprecated test
afontcu Jun 8, 2020
b80926b
Cleanup template
afontcu Jun 8, 2020
2b07210
Fix autocleanup tests
afontcu Jun 8, 2020
9e26a03
Fix warning on onsubmit jsdom
afontcu Aug 23, 2020
8483889
Bump vue deps
afontcu Aug 23, 2020
a333bba
Fix failing stubs tests
afontcu Aug 23, 2020
690df45
Update deps
afontcu Oct 9, 2020
553a8b0
Rename lifecycle method
afontcu Oct 9, 2020
1a6274d
Fix directive example
afontcu Oct 9, 2020
34e276e
Remove updateProps
afontcu Oct 9, 2020
e61a9ae
Simplify the slots example
afontcu Oct 9, 2020
347a30b
Fix functional tests
afontcu Oct 9, 2020
108b8b6
Add POC for Vuex 4
afontcu Oct 11, 2020
e8b1b02
Update vue-i18n example
afontcu Oct 11, 2020
49f6639
Fix snapshots
afontcu Oct 13, 2020
1496dd1
Fix vee-validate tests
afontcu Oct 13, 2020
90c3772
Add missing test for unmount
afontcu Oct 13, 2020
13497b3
Remove propsData
afontcu Oct 13, 2020
e054728
Remove isUnmounted
afontcu Oct 13, 2020
6e490c0
Add composition API example
afontcu Oct 13, 2020
5c98617
Bump deps
afontcu Oct 17, 2020
93768a4
Remove localVue references
afontcu Oct 17, 2020
47d3f0a
Bump vtu-next
afontcu Oct 18, 2020
8e06631
Comment out unused features (router)
afontcu Oct 18, 2020
38f53ae
Update deps
afontcu Oct 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,50 @@
"vue.js 2",
"vue.js 2 testing",
"vue 2",
"vue 2 testing"
"vue 2 testing",
"vue.js 3",
"vue.js 3 testing",
"vue 3",
"vue 3 testing"
],
"author": "Daniel Cook",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.11.2",
"@testing-library/dom": "^7.24.3",
"@types/testing-library__vue": "^5.0.0",
"@vue/test-utils": "^1.1.0"
"@babel/runtime": "^7.12.1",
"@testing-library/dom": "^7.26.3",
"@types/testing-library__vue": "*",
"@vue/test-utils": "^2.0.0-beta.7",
"lodash.merge": "^4.6.2"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.11.5",
"@testing-library/jest-dom": "^5.11.4",
"@babel/plugin-transform-runtime": "^7.12.1",
"@testing-library/jest-dom": "^5.11.5",
"@vue/compiler-sfc": "^3.0.2",
"apollo-boost": "^0.4.9",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"axios": "^0.20.0",
"eslint-plugin-vue": "^6.2.2",
"graphql": "^15.3.0",
"graphql": "^15.4.0",
"graphql-tag": "^2.11.0",
"isomorphic-unfetch": "^3.0.0",
"isomorphic-unfetch": "^3.1.0",
"jest-serializer-vue": "^2.0.2",
"kcd-scripts": "^6.5.1",
"lodash.merge": "^4.6.2",
"msw": "^0.21.2",
"kcd-scripts": "^6.6.0",
"msw": "^0.21.3",
"portal-vue": "^2.1.7",
"vee-validate": "^2.2.15",
"vue": "^2.6.12",
"vue-apollo": "^3.0.4",
"vue-i18n": "^8.21.1",
"vue-jest": "^4.0.0-rc.0",
"vue-router": "^3.4.5",
"vue-template-compiler": "^2.6.12",
"vuetify": "^2.3.10",
"vuex": "^3.5.1"
"typescript": "^3.8.3",
"vee-validate": "^4.0.0-beta.16",
"vue": "^3.0.2",
"vue-apollo": "^3.0.5",
"vue-i18n": "^9.0.0-beta.6",
"vue-jest": "^5.0.0-alpha.5",
"vue-router": "^4.0.0-rc.1",
"vuetify": "^2.3.16",
"vuex": "^4.0.0-rc.1"
},
"peerDependencies": {
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
"vue": "^3.0",
"@vue/compiler-sfc": "^3.0"
},
"husky": {
"hooks": {
Expand Down
9 changes: 4 additions & 5 deletions src/__tests__/auto-cleanup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {render} from '@testing-library/vue'
import '@testing-library/jest-dom'

// This just verifies that by importing VTL in an environment which supports
// This verifies that by importing VTL in an environment which supports
// afterEach (like jest) we'll get automatic cleanup between tests.
test('render the first component', () => {
render({
template: `<h1>Hello World</h1>`,
})
test('renders the component', () => {
render({template: `<h1>Hello World</h1>`})

expect(document.body.innerHTML).toMatchInlineSnapshot(`
<div>
<h1>Hello World</h1>
Expand Down
18 changes: 6 additions & 12 deletions src/__tests__/axios-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {render, fireEvent} from '@testing-library/vue'
import Component from './components/Fetch.vue'

test('mocks an API call when load-greeting is clicked', async () => {
axiosMock.get.mockImplementationOnce(() =>
Promise.resolve({
data: {greeting: 'hello there'},
}),
)
axiosMock.get.mockResolvedValueOnce({
data: {greeting: 'hello there'},
})

const {html, getByText} = render(Component, {props: {url: '/greeting'}})

Expand All @@ -22,11 +20,7 @@ test('mocks an API call when load-greeting is clicked', async () => {
// that Snapshot Testing should not be treated as a replacement for regular
// tests.
// More about the topic: https://twitter.com/searls/status/919594505938112512
expect(html()).toMatchInlineSnapshot(`
<div><button>
Fetch
</button> <span>
hello there
</span></div>
`)
expect(html()).toMatchInlineSnapshot(
`<div><button> Fetch </button><span>hello there</span></div>`,
)
})
42 changes: 22 additions & 20 deletions src/__tests__/cleanup-throw.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import {render, cleanup} from '@testing-library/vue'
import Vue from 'vue'
test.todo('check if this test still makes sense')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #142


test('cleanup re-throws errors from async lifecycle hooks', async () => {
const err = new Error('foo')
render({
async mounted() {
await new Promise((resolve, reject) => {
reject(err)
})
},
template: `<h1>Hello World</h1>`,
})
// thrown errors are logged redundantly by vue-test-utils injected Vue.config.errorHandler
// mute console
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
// import {render, cleanup} from '@testing-library/vue'
// import {nextTick} from 'vue'

await Vue.nextTick()
expect(cleanup).toThrow(err)
// test('cleanup re-throws errors from async lifecycle hooks', async () => {
// const err = new Error('foo')
// render({
// async mounted() {
// await new Promise((resolve, reject) => {
// reject(err)
// })
// },
// template: `<h1>Hello World</h1>`,
// })
// // thrown errors are logged redundantly by vue-test-utils injected Vue.config.errorHandler
// // mute console
// const spy = jest.spyOn(console, 'error').mockImplementation(() => {})

// unmute console
spy.mockReset()
})
// await nextTick()
// expect(cleanup).toThrow(err)

// // unmute console
// spy.mockReset()
// })
16 changes: 0 additions & 16 deletions src/__tests__/components/Card.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
<template>
<div class="card">
<slot name="header" />
<slot :content="content">
<!-- Fallback content if no default slot is given -->
<p>Nothing used the {{ content }}</p>
</slot>
<slot name="footer" />
</div>
</template>

<script>
// For the sake of demoing scopedSlots, this Card component
// passes a simple string down to its default slot.
export default {
data() {
return {
content: 'Scoped content!'
}
}
}
</script>
146 changes: 73 additions & 73 deletions src/__tests__/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
<template>
<div>
<h1>Movie Review</h1>
<form @submit.prevent="submit">
<label for="movie-input">Title of the movie</label>
<input id="movie-input" v-model="title" name="title" />
<label id="review-textarea">Your review</label>
<textarea
v-model="review"
name="review-textarea"
placeholder="Write an awesome review"
aria-labelledby="review-textarea"
/>
<label>
<input v-model="rating" type="radio" value="3" />
Wonderful
</label>
<label>
<input v-model="rating" type="radio" value="2" />
Average
</label>
<label>
<input v-model="rating" type="radio" value="1" />
Awful
</label>
<label id="recommend-label">Would you recommend this movie?</label>
<input
id="recommend"
v-model="recommend"
type="checkbox"
name="recommend"
/>
<button :disabled="submitDisabled" type="submit">
Submit
</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
title: '',
review: '',
rating: '1',
recommend: false,
}
},
computed: {
submitDisabled() {
return !this.title || !this.review
},
},
methods: {
submit() {
if (this.submitDisabled) return
this.$emit('submit', {
title: this.title,
review: this.review,
rating: this.rating,
recommend: this.recommend,
})
},
},
}
</script>
<template>
<div>
<h1>Movie Review</h1>
<form onsubmit="return false">
<label for="movie-input">Title of the movie</label>
<input id="movie-input" v-model="title" name="title" />

<label id="review-textarea">Your review</label>
<textarea
v-model="review"
name="review-textarea"
placeholder="Write an awesome review"
aria-labelledby="review-textarea"
/>

<label>
<input v-model="rating" type="radio" value="3" />
Wonderful
</label>
<label>
<input v-model="rating" type="radio" value="2" />
Average
</label>
<label>
<input v-model="rating" type="radio" value="1" />
Awful
</label>

<label id="recommend-label">Would you recommend this movie?</label>
<input
id="recommend"
v-model="recommend"
type="checkbox"
name="recommend"
/>

<button :disabled="submitDisabled" type="submit" @click="submit">
Submit
</button>
</form>
</div>
</template>

<script>
export default {
data() {
return {
title: '',
review: '',
rating: '1',
recommend: false,
}
},
computed: {
submitDisabled() {
return !this.title || !this.review
},
},

methods: {
submit() {
if (this.submitDisabled) return

this.$emit('submit', {
title: this.title,
review: this.review,
rating: this.rating,
recommend: this.recommend,
})
},
},
}
</script>
Loading