From d9b1b5e0c049d07e21b65e00668dbde7349e26c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Sat, 31 Oct 2020 20:33:52 +0100 Subject: [PATCH 01/39] feat: Update to Vue 3.0 and Vue Test Utils 2.0 (#137) (#163) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: - Snapshots are potentially different due to whitespaces. - Some options such as stubs are now moved to `global.stubs`. - Previous usage of vue instance as a parameter for the callback function is not replaced with global `config` options (for example, `global.directives`). - `isUnmounted` is gone. - `updateProps` is now called setProps to align with VTU. Some of the missing steps is to provide support to Vue Router, and also to update libraries of the ecosystem to their Vue 3 version. This is an exciting release! 🎉 It marks the first release aiming to support Vue 3 and Vue Test Utils 2. Please [head to the PR](https://github.com/testing-library/vue-testing-library/pull/137) to get more information, and feel free to open up issues and PRs to fix missing features / ports 😄 --- package.json | 52 ++++--- src/__tests__/auto-cleanup.js | 9 +- src/__tests__/axios-mock.js | 18 +-- src/__tests__/cleanup-throw.js | 42 ++--- src/__tests__/components/Card.vue | 16 -- src/__tests__/components/Form.vue | 146 +++++++++--------- src/__tests__/components/StopWatch.vue | 76 ++++----- src/__tests__/components/Store/store.js | 6 +- src/__tests__/components/Stubs.vue | 15 +- src/__tests__/components/Translations.vue | 18 +-- src/__tests__/components/Validate.vue | 53 ++++--- src/__tests__/directive.js | 14 +- .../directives/uppercase-directive.js | 10 +- src/__tests__/fire-event.js | 36 +++-- src/__tests__/functional.js | 19 +-- src/__tests__/render.js | 12 ++ src/__tests__/set-props.js | 51 ++++++ src/__tests__/slots.js | 21 +-- src/__tests__/stopwatch.js | 17 -- src/__tests__/stubs.js | 14 +- src/__tests__/update-props.js | 23 --- src/__tests__/validate-plugin.js | 31 ++-- src/__tests__/vue-apollo.js | 119 +++++++------- src/__tests__/vue-i18n.js | 41 ++--- src/__tests__/vue-portal.js | 54 ++++--- src/__tests__/vue-router-mocha.js | 28 ++-- src/__tests__/vue-router.js | 56 +++---- src/__tests__/vueI18n.js | 78 +++++----- src/__tests__/vuetify.js | 115 +++++++------- src/__tests__/vuex.js | 7 +- src/vue-testing-library.js | 88 +++++------ 31 files changed, 637 insertions(+), 648 deletions(-) create mode 100644 src/__tests__/set-props.js delete mode 100644 src/__tests__/update-props.js diff --git a/package.json b/package.json index d579d2f3..273dd82a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/__tests__/auto-cleanup.js b/src/__tests__/auto-cleanup.js index 8d5412ae..8255c083 100644 --- a/src/__tests__/auto-cleanup.js +++ b/src/__tests__/auto-cleanup.js @@ -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: `

Hello World

`, - }) +test('renders the component', () => { + render({template: `

Hello World

`}) + expect(document.body.innerHTML).toMatchInlineSnapshot(`

Hello World

diff --git a/src/__tests__/axios-mock.js b/src/__tests__/axios-mock.js index 39e51bab..c4f066d8 100644 --- a/src/__tests__/axios-mock.js +++ b/src/__tests__/axios-mock.js @@ -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'}}) @@ -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(` -
- hello there -
- `) + expect(html()).toMatchInlineSnapshot( + `
hello there
`, + ) }) diff --git a/src/__tests__/cleanup-throw.js b/src/__tests__/cleanup-throw.js index b8ba9fd7..828820f2 100644 --- a/src/__tests__/cleanup-throw.js +++ b/src/__tests__/cleanup-throw.js @@ -1,23 +1,25 @@ -import {render, cleanup} from '@testing-library/vue' -import Vue from 'vue' +test.todo('check if this test still makes sense') -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: `

Hello World

`, - }) - // 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: `

Hello World

`, +// }) +// // 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() +// }) diff --git a/src/__tests__/components/Card.vue b/src/__tests__/components/Card.vue index 9174e499..c62ee1b4 100644 --- a/src/__tests__/components/Card.vue +++ b/src/__tests__/components/Card.vue @@ -1,22 +1,6 @@ - - diff --git a/src/__tests__/components/Form.vue b/src/__tests__/components/Form.vue index 78b83ca9..809bf316 100644 --- a/src/__tests__/components/Form.vue +++ b/src/__tests__/components/Form.vue @@ -1,73 +1,73 @@ -