From c41507f64f7aa2996c63892cd63b733928edff17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 16:58:15 +0200 Subject: [PATCH 01/43] Bump Vue and VTU --- package.json | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index d579d2f3..cffb4237 100644 --- a/package.json +++ b/package.json @@ -35,15 +35,19 @@ "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.9.6", + "@types/testing-library__vue": "*", + "@vue/test-utils": "^2.0.0-alpha.3" }, "devDependencies": { "@babel/plugin-transform-runtime": "^7.11.5", @@ -51,6 +55,8 @@ "apollo-boost": "^0.4.9", "apollo-cache-inmemory": "^1.6.6", "axios": "^0.20.0", + "apollo-client": "^2.6.10", + "@vue/compiler-sfc": "^3.0", "eslint-plugin-vue": "^6.2.2", "graphql": "^15.3.0", "graphql-tag": "^2.11.0", @@ -60,19 +66,20 @@ "lodash.merge": "^4.6.2", "msw": "^0.21.2", "portal-vue": "^2.1.7", + "typescript": "^3.8.3", "vee-validate": "^2.2.15", - "vue": "^2.6.12", + "vue": "^3.0", "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", + "vue-template-compiler": "^3.0", "vuetify": "^2.3.10", "vuex": "^3.5.1" }, "peerDependencies": { - "vue": "^2.6.10", - "vue-template-compiler": "^2.6.10" + "vue": "^3.0", + "@vue/compiler-sfc": "^3.0" }, "husky": { "hooks": { From a1b91eda50ba27813ebc66113592bf930ef5c7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:00:13 +0200 Subject: [PATCH 02/43] Identify TODOs --- src/vue-testing-library.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index a7cd4472..66f2e2df 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -1,5 +1,6 @@ /* eslint-disable testing-library/no-wait-for-empty-callback */ -import {createLocalVue, mount} from '@vue/test-utils' +import {mount} from '@vue/test-utils' +// import {createLocalVue, mount} from '@vue/test-utils' import { getQueriesForElement, @@ -21,6 +22,7 @@ function render( } = {}, configurationCb, ) { + // TODO: Can we simplify this by using attachTo? const div = document.createElement('div') const baseElement = customBaseElement || customContainer || document.body const container = customContainer || baseElement.appendChild(div) @@ -28,28 +30,30 @@ function render( const attachTo = document.createElement('div') container.appendChild(attachTo) - const localVue = createLocalVue() + // const localVue = createLocalVue() let vuexStore = null let router = null let additionalOptions = {} + // TODO: Fix VTL + Vuex (v4?) if (store) { const Vuex = require('vuex') - localVue.use(Vuex) + // localVue.use(Vuex) vuexStore = new Vuex.Store(store) } + // TODO: Fix VTL + Vue-router(next?) if (routes) { const requiredRouter = require('vue-router') const VueRouter = requiredRouter.default || requiredRouter - localVue.use(VueRouter) + // localVue.use(VueRouter) router = new VueRouter({ routes, }) } if (configurationCb && typeof configurationCb === 'function') { - additionalOptions = configurationCb(localVue, vuexStore, router) + additionalOptions = configurationCb(vuexStore, router) } if (!mountOptions.propsData && !!mountOptions.props) { @@ -58,10 +62,10 @@ function render( } const wrapper = mount(TestComponent, { - localVue, - router, + // localVue, + // router, + // store: vuexStore, attachTo, - store: vuexStore, ...mountOptions, ...additionalOptions, }) @@ -74,10 +78,14 @@ function render( baseElement, debug: (el = baseElement) => Array.isArray(el) ? el.forEach(e => logDOM(e)) : logDOM(el), - unmount: () => wrapper.destroy(), - isUnmounted: () => wrapper.vm._isDestroyed, + unmount: () => wrapper.unmount(), + // isUnmounted: () => wrapper.vm._isDestroyed, html: () => wrapper.html(), emitted: () => wrapper.emitted(), + + // TODO: Is this unnecessary now? No need to await for a tick because + // setProps() handles it for us now. + // We can simply expose setProps. updateProps: _ => { wrapper.setProps(_) return waitFor(() => {}) From 76c662486271d37a30f62cdba40052bee5e99216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:01:31 +0200 Subject: [PATCH 03/43] Allow propsData (mark as breaking change) --- src/vue-testing-library.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index 66f2e2df..c31f20ed 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -56,9 +56,12 @@ function render( additionalOptions = configurationCb(vuexStore, router) } - if (!mountOptions.propsData && !!mountOptions.props) { - mountOptions.propsData = mountOptions.props - delete mountOptions.props + // If `propsData` is provided, rename it to `props` + // Since this is gonna be a breaking channge, we can remove the + // whole thing. + if (!mountOptions.props && !!mountOptions.propsData) { + mountOptions.props = mountOptions.propsData + delete mountOptions.propsData } const wrapper = mount(TestComponent, { From ecfc251bbebd04b7016c7906db9685c32be90278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:01:48 +0200 Subject: [PATCH 04/43] Remove removed method --- src/vue-testing-library.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index c31f20ed..fcac0c23 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -1,6 +1,5 @@ /* eslint-disable testing-library/no-wait-for-empty-callback */ import {mount} from '@vue/test-utils' -// import {createLocalVue, mount} from '@vue/test-utils' import { getQueriesForElement, From e9d5f9520106550a0b30b507e4296b163e8842f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:05:45 +0200 Subject: [PATCH 05/43] Fix fire-event tests --- src/__tests__/fire-event.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/__tests__/fire-event.js b/src/__tests__/fire-event.js index bced573f..a9b6d537 100644 --- a/src/__tests__/fire-event.js +++ b/src/__tests__/fire-event.js @@ -1,3 +1,4 @@ +import {h} from 'vue' import {render, fireEvent} from '@testing-library/vue' import Button from './components/Button' @@ -120,6 +121,8 @@ const eventTypes = [ }, ] +const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1) + // For each event type, we assert that the right events are being triggered // when the associated fireEvent method is called. eventTypes.forEach(({type, events, elementType = 'input', init}) => { @@ -128,21 +131,20 @@ eventTypes.forEach(({type, events, elementType = 'input', init}) => { it(`triggers ${eventName}`, async () => { const testId = `${type}-${eventName}` const spy = jest.fn() + const eventNameHandler = `on${capitalize(eventName)}` - // Render an element with a listener of the event under testing and a - // test-id attribute, so that we can get the DOM node afterwards. - const {getByTestId} = render({ - render(h) { + const componentWithEvent = { + render() { return h(elementType, { - on: { - [eventName.toLowerCase()]: spy, - }, - attrs: { - 'data-testid': testId, - }, + [eventNameHandler]: spy, + 'data-testid': testId, }) }, - }) + } + + // Render an element with a listener of the event under testing and a + // test-id attribute, so that we can get the DOM node afterwards. + const {getByTestId} = render(componentWithEvent) const elem = getByTestId(testId) @@ -157,13 +159,13 @@ eventTypes.forEach(({type, events, elementType = 'input', init}) => { test('triggers dblclick on doubleClick', async () => { const spy = jest.fn() - const {getByRole} = render({ - render(h) { - return h('button', { - on: {dblclick: spy}, - }) + const componentWithDblClick = { + render() { + return h('button', {onDblClick: spy}, 'Click me') }, - }) + } + + const {getByRole} = render(componentWithDblClick) const elem = getByRole('button') From 9d1663e88da47b0bfc962d438dbc5434dbfeb897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:06:23 +0200 Subject: [PATCH 06/43] Add basic TS config (is this needed?) --- tsconfig.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..e7c8019e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es5", + "outDir": "dist", + "module": "esnext", + "moduleResolution": "node", + "esModuleInterop": true + }, + "include": ["src"] +} From 3659de3f66875c424c6b9aca33abe59e9bde9b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:13:04 +0200 Subject: [PATCH 07/43] Add link to related issue --- src/vue-testing-library.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index fcac0c23..c9b0e2e2 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -22,6 +22,7 @@ function render( configurationCb, ) { // TODO: Can we simplify this by using attachTo? + // Related: https://github.com/vuejs/vue-test-utils-next/issues/10 const div = document.createElement('div') const baseElement = customBaseElement || customContainer || document.body const container = customContainer || baseElement.appendChild(div) From e2ae9c8546fe72dd81ded01d87a8dd38d79dd8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Mon, 27 Apr 2020 17:22:20 +0200 Subject: [PATCH 08/43] Fix form.vue (not sure how this is related to Vue3? --- src/__tests__/components/Form.vue | 146 +++++++++++++++--------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/src/__tests__/components/Form.vue b/src/__tests__/components/Form.vue index 78b83ca9..d4e7ab85 100644 --- a/src/__tests__/components/Form.vue +++ b/src/__tests__/components/Form.vue @@ -1,73 +1,73 @@ -