Skip to content

Commit

Permalink
fix: attach emit listener after createApp is called (#437)
Browse files Browse the repository at this point in the history
* fix: attach emit listener after createApp is called

* chore: lint
  • Loading branch information
lmiller1990 authored Mar 3, 2021
1 parent c667907 commit 9c2ad02
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@rollup/plugin-replace": "^2.4.1",
"@types/jest": "26.0.20",
"@types/node": "14.14.31",
"@vue/compiler-sfc": "3.0.6",
"@vue/compiler-sfc": "3.0.7",
"babel-jest": "^26.6.3",
"babel-preset-jest": "^26.6.2",
"dom-event-types": "^1.0.0",
Expand All @@ -38,7 +38,7 @@
"tsd": "0.14.0",
"typescript": "^4.2.2",
"vitepress": "^0.12.2",
"vue": "3.0.6",
"vue": "3.0.7",
"vue-class-component": "^8.0.0-rc.1",
"vue-jest": "^5.0.0-alpha.8",
"vue-router": "^4.0.4",
Expand Down
7 changes: 4 additions & 3 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,13 @@ export function mount(
return vm.$nextTick()
}

// add tracking for emitted events
attachEmitListener()

// create the app
const app = createApp(Parent)

// add tracking for emitted events
// this must be done after `createApp`: https://github.com/vuejs/vue-test-utils-next/issues/436
attachEmitListener()

// global mocks mixin
if (global?.mocks) {
const mixin = {
Expand Down
27 changes: 25 additions & 2 deletions tests/emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('emitted', () => {
console.warn = consoleWarnSave
})

it('captures events emitted via this.$emit', () => {
it('captures events emitted via this.$emit', async () => {
const Component = defineComponent({
render() {
return h('div', [
Expand All @@ -33,7 +33,7 @@ describe('emitted', () => {
expect(wrapper.emitted()).toEqual({})
expect(wrapper.emitted().hello).toEqual(undefined)

wrapper.find('button').trigger('click')
await wrapper.find('button').trigger('click')
expect(wrapper.emitted().hello[0]).toEqual(['foo', 'bar'])

wrapper.find('button').trigger('click')
Expand Down Expand Up @@ -274,4 +274,27 @@ describe('emitted', () => {

expect(wrapper.emitted().compositionstart).not.toBe(undefined)
})

it('https://github.com/vuejs/vue-test-utils-next/issues/436', async () => {
const Foo = defineComponent({
name: 'Foo',
emits: ['foo'],
setup(_, ctx) {
return () =>
h(
'div',
{
onClick: () => {
ctx.emit('foo', 'bar')
}
},
'hello world'
)
}
})

const wrapper = mount(Foo)
await wrapper.trigger('click')
expect(wrapper.emitted('foo')).toHaveLength(1)
})
})
91 changes: 89 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,17 @@
estree-walker "^2.0.1"
source-map "^0.6.1"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.7.tgz#421782a4c67cc3f2b7c30457ef446d74f8524f74"
integrity sha512-JFohgBXoyUc3mdeI2WxlhjQZ5fakfemJkZHX8Gu/nFbEg3+lKVUZmNKWmmnp9aOzJQZKoj77LjmFxiP+P+7lMQ==
dependencies:
"@babel/parser" "^7.12.0"
"@babel/types" "^7.12.0"
"@vue/shared" "3.0.7"
estree-walker "^2.0.1"
source-map "^0.6.1"

"@vue/[email protected]":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.5.tgz#7885a13e6d18f64dde8ebceec052ed2c102696c2"
Expand All @@ -1524,7 +1535,37 @@
"@vue/compiler-core" "3.0.6"
"@vue/shared" "3.0.6"

"@vue/[email protected]", "@vue/compiler-sfc@^3.0.5":
"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.7.tgz#54d2e12fb9a7aff53abd19dac2c2679533f0c919"
integrity sha512-VnIH9EbWQm/Tkcp+8dCaNVsVvhm/vxCrIKWRkXY9215hTqOqQOvejT8IMjd2kc++nIsYMsdQk6H9qqBvoLe/Cw==
dependencies:
"@vue/compiler-core" "3.0.7"
"@vue/shared" "3.0.7"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.7.tgz#900414750cc726553b870490f48073451fd14f07"
integrity sha512-37/QILpGE+J3V+bP9Slg9e6xGqfk+MmS2Yj8ChR4fS0/qWUU/YoYHE0GPIzjmBdH0JVOOmJqunxowIXmqNiHng==
dependencies:
"@babel/parser" "^7.12.0"
"@babel/types" "^7.12.0"
"@vue/compiler-core" "3.0.7"
"@vue/compiler-dom" "3.0.7"
"@vue/compiler-ssr" "3.0.7"
"@vue/shared" "3.0.7"
consolidate "^0.16.0"
estree-walker "^2.0.1"
hash-sum "^2.0.0"
lru-cache "^5.1.1"
magic-string "^0.25.7"
merge-source-map "^1.1.0"
postcss "^8.1.10"
postcss-modules "^4.0.0"
postcss-selector-parser "^6.0.4"
source-map "^0.6.1"

"@vue/compiler-sfc@^3.0.5":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.6.tgz#3945f73a93d52868799f1e332a75bb8849976ac9"
integrity sha512-g1tkswnhtiJpj4ELQ3SzeGxtOd0t8E5GkT+n2VlElEnTI1BzueSvr41D5QthnUS+TNWZd52ZnPtdaNz+Lfum1w==
Expand Down Expand Up @@ -1562,13 +1603,28 @@
"@vue/compiler-dom" "3.0.6"
"@vue/shared" "3.0.6"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.7.tgz#28b85d497381d75fe44234057b140b0065ca9dbf"
integrity sha512-nHRbHeSpfXwjypettjrA16TjgfDcPEwq3m/zHnGyLC1QqdLtklXmpSM43/CPwwTCRa/qdt0pldJf22MiCEuTSQ==
dependencies:
"@vue/compiler-dom" "3.0.7"
"@vue/shared" "3.0.7"

"@vue/[email protected]":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.6.tgz#7b16f3d5d04cc55028085fff0bb8475cc0e32991"
integrity sha512-hX8PnZayNMoljWSYrZW0OclQnRaMoHxvi5eeFVFPDr7+tzBeiftmmozKttxxCLoDxBWX1B4gNc237DIcYU63Lw==
dependencies:
"@vue/shared" "3.0.6"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.0.7.tgz#e6ccc7bef7fc10b0972e4d974bad71679d3b26ad"
integrity sha512-FotWcNNaKhqpFZrdgsUOZ1enlJ5lhTt01CNTtLSyK7jYFgZBTuw8vKsEutZKDYZ1XKotOfoeO8N3pZQqmM6Etw==
dependencies:
"@vue/shared" "3.0.7"

"@vue/[email protected]":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.6.tgz#d16779b5664593f1d25be677fb1b1968024aa532"
Expand All @@ -1577,6 +1633,14 @@
"@vue/reactivity" "3.0.6"
"@vue/shared" "3.0.6"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.0.7.tgz#d44c0b0a57d7e392912a87362a4430ccf446ecea"
integrity sha512-DBAZAwVvdmMXuyd6/9qqj/kYr/GaLTmn1L2/QLxLwP+UfhIboiTSBc/tUUb8MRk7Bb98GzNeAWkkT6AfooS3dQ==
dependencies:
"@vue/reactivity" "3.0.7"
"@vue/shared" "3.0.7"

"@vue/[email protected]":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.6.tgz#e7d6c61913d871f1f020a9a81b558c8fcbeba8c6"
Expand All @@ -1586,6 +1650,15 @@
"@vue/shared" "3.0.6"
csstype "^2.6.8"

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.0.7.tgz#b70668d729020bc4ad608c20367223f259576ba6"
integrity sha512-Oij4ruOtnpQpCj+/Q3JPzgpTJ1Q7+N67pA53A8KVITEtxfvKL46NN6dhAZ5NGqwX6RWZpYqWQNewITeF0pHr8g==
dependencies:
"@vue/runtime-core" "3.0.7"
"@vue/shared" "3.0.7"
csstype "^2.6.8"

"@vue/server-renderer@^3.0.5":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@vue/server-renderer/-/server-renderer-3.0.5.tgz#1197e7d7b7874e15de284798a3932ec425ffe593"
Expand All @@ -1604,6 +1677,11 @@
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.6.tgz#d65576430fc4ad383dc7c829118798e5169178d4"
integrity sha512-c37C60HpelUZIx+SNZVEINSxkFzQYhIXFg5AynnIA4QDBmY4iSPoACfGSwSUTCTKImukPeCgY2oqRJVP3R1Mnw==

"@vue/[email protected]":
version "3.0.7"
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.7.tgz#96d52988efc07444c108c7c6803ba7cc93e40045"
integrity sha512-dn5FyfSc4ky424jH4FntiHno7Ss5yLkqKNmM/NXwANRnlkmqu74pnGetexDFVG5phMk9/FhwovUZCWGxsotVKg==

abab@^2.0.0, abab@^2.0.3:
version "2.0.5"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a"
Expand Down Expand Up @@ -6572,7 +6650,16 @@ vue-router@^4.0.4:
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.4.tgz#ad9b4b7bbdad622407b4ff189b1646f48c1e9053"
integrity sha512-uN6PDEaYdU9aRO7mU+Dkr1uaY49hV3fucEDG/Vre/Qj8ct3RoJS16vcPrvKVzn69zDDjBV5b9Xw7fZA9r6b/Iw==

[email protected], vue@^3.0.5:
[email protected]:
version "3.0.7"
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.7.tgz#8bcff51f8be570f9e4ce8cc5f52e2ab0fe3c74a1"
integrity sha512-8h4TikD+JabbMK9aRlBO4laG0AtNHRPHynxYgWZ9sq1YUPfzynd9Jeeb27XNyZytC7aCQRX9xe1+TQJuc181Tw==
dependencies:
"@vue/compiler-dom" "3.0.7"
"@vue/runtime-dom" "3.0.7"
"@vue/shared" "3.0.7"

vue@^3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.6.tgz#2c16ed4bb66f16d6c6f6eaa3b7d5835a76598049"
integrity sha512-fgjbe/+f1EsqG7ZbaFSnxdzQXF2DKoFCdJlPxZZJy9XMtyXS6SY8pGzLi8WYb4zmsPLHvTZz4bHW30kFDk7vfA==
Expand Down

0 comments on commit 9c2ad02

Please sign in to comment.