Skip to content

Commit 832c234

Browse files
wip(tests): add tests for vue-template-es2015-compiler fakeBuble.mjs
1 parent b7bf669 commit 832c234

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

tests/basic.test.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,120 @@ const { defaultFilesVue2, defaultFiles, createPage } = require('./testsTools.js'
682682
});
683683

684684

685+
// https://github.com/vuejs/vue-template-es2015-compiler/blob/master/test.js
686+
687+
test('should pass vue-template-es2015-compiler test "should work"', async () => {
688+
689+
const { page, output } = await createPage({
690+
files: {
691+
...files,
692+
693+
'/component.vue': `
694+
<template>
695+
<div><div>{{ foo }}</div><div v-for="{ name } in items">{{ name }}</div><div v-bind="{ ...a, ...b }"/></div>
696+
</template>
697+
<script>
698+
export default {
699+
data() {
700+
701+
return {
702+
foo: 'hello',
703+
items: [
704+
{ name: 'foo' },
705+
{ name: 'bar' }
706+
],
707+
a: { id: 'foo' },
708+
b: { class: 'bar' }
709+
}
710+
}
711+
}
712+
</script>
713+
`,
714+
}
715+
});
716+
717+
await expect(page.$eval('#app', el => el.innerHTML)).resolves.toMatch(`<div><div>hello</div><div>foo</div><div>bar</div><div id="foo" class="bar"></div></div>`);
718+
await page.close();
719+
});
720+
721+
722+
test('should pass vue-template-es2015-compiler test "arg spread"', async () => {
723+
724+
const { page, output } = await createPage({
725+
files: {
726+
...files,
727+
728+
'/component.vue': `
729+
<template>
730+
<button @click="(...args) => { store.foo(...args) }">Go</button>
731+
</template>
732+
`,
733+
}
734+
});
735+
736+
// original Vue2 expected match: `_vm.store.foo.apply(_vm.store, args)`
737+
// Vue3 expected match: `_ctx.store.foo(...args)`
738+
await expect(page.$eval('#app', el => el.vueApp.$options.render.toString()) ).resolves.toMatch(`.store.foo(...args)`);
739+
await page.close();
740+
});
741+
742+
743+
if ( vueTarget === 2 ) { // Vue 3 has no $scopedSlots
744+
745+
test('should pass vue-template-es2015-compiler test "rest spread in scope position"', async () => {
746+
747+
const { page, output } = await createPage({
748+
files: {
749+
...files,
750+
751+
'/component.vue': `
752+
<template>
753+
<foo v-slot="{ foo, ...rest }">{{ rest }}</foo>
754+
</template>
755+
<script>
756+
export default {
757+
components: {
758+
foo: {
759+
render(h) {
760+
return h('div', this.$scopedSlots.default({
761+
foo: 1,
762+
bar: 2,
763+
baz: 3
764+
}))
765+
}
766+
}
767+
}
768+
}
769+
</script>
770+
`,
771+
}
772+
});
773+
774+
await expect(page.$eval('#app', el => el.innerHTML)).resolves.toMatch( JSON.stringify({ bar: 2, baz: 3 }, null, 2));
775+
await page.close();
776+
});
777+
}
778+
779+
if ( vueTarget === 2 ) { // Vue3 is not concerned
780+
781+
test.only('should pass vue-template-es2015-compiler test "trailing function comma"', async () => {
782+
783+
const { page, output } = await createPage({
784+
files: {
785+
...files,
786+
787+
'/component.vue': `
788+
<template>
789+
<button @click="spy(1,)" />
790+
</template>
791+
`,
792+
}
793+
});
794+
795+
await expect(page.$eval('#app', el => el.vueApp.$options.render.toString()) ).resolves.toMatch(`return _vm.spy(1);`);
796+
await page.close();
797+
});
798+
685799

686800
});
687801

tests/testsTools.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ const defaultFiles = {
198198
199199
optionsOverride(options)
200200
201-
boot({ options, createApp, mountApp, Vue });
201+
boot({ options, createApp, mountApp, Vue })
202+
.then(app => app.$el.parentNode.vueApp = app);
202203
203204
//window._done && window._done();
204205
@@ -251,7 +252,8 @@ const defaultFilesVue2 = {
251252
252253
optionsOverride(options)
253254
254-
boot({ options, createApp, mountApp, Vue });
255+
boot({ options, createApp, mountApp, Vue })
256+
.then(app => app.$el.parentNode.vueApp = app);
255257
256258
//window._done && window._done();
257259

0 commit comments

Comments
 (0)