test: overrideProps snapshot

This commit is contained in:
Amour1688 2020-09-09 17:19:36 +08:00
parent e16695d87e
commit b23cfe0020
3 changed files with 41 additions and 5 deletions

View File

@ -11,7 +11,7 @@ export type State = {
opts: Opts;
}
interface Opts {
export interface Opts {
transformOn?: boolean;
optimize?: boolean;
mergeProps?: boolean;

View File

@ -79,6 +79,21 @@ withDirectives(createVNode(\\"input\\", {
}, null, 8, [\\"onUpdate:modelValue\\"]), [[vModelText, test]]);"
`;
exports[`override props multiple: multiple 1`] = `
"import { resolveComponent, createVNode } from \\"vue\\";
createVNode(resolveComponent(\\"A\\"), {
\\"loading\\": true,
...a,
\\"class\\": \\"x\\",
\\"style\\": x
}, null);"
`;
exports[`override props single: single 1`] = `
"import { createVNode } from \\"vue\\";
createVNode(\\"div\\", a, null);"
`;
exports[`reassign variable as component: reassign variable as component 1`] = `
"import { defineComponent, createVNode } from \\"vue\\";
let a = 1;

View File

@ -1,12 +1,14 @@
import { transform } from '@babel/core';
import JSX from '../src';
import JSX, { Opts } from '../src';
const transpile = (source: string) => new Promise((resolve, reject) => transform(
const transpile = (
source: string, options: Opts = {},
) => new Promise((resolve, reject) => transform(
source,
{
filename: '',
presets: null,
plugins: [[JSX, { optimize: true }]],
plugins: [[JSX, options]],
configFile: false,
}, (error, result) => {
if (error) {
@ -138,7 +140,26 @@ tests.forEach((
test(
name,
async () => {
expect(await transpile(from)).toMatchSnapshot(name);
expect(await transpile(from, { optimize: true })).toMatchSnapshot(name);
},
);
});
const overridePropsTests = [{
name: 'single',
from: '<div {...a}></div>',
}, {
name: 'multiple',
from: '<A loading {...a} class="x" style={x}></A>',
}];
overridePropsTests.forEach((
{ name, from },
) => {
test(
`override props ${name}`,
async () => {
expect(await transpile(from, { mergeProps: false })).toMatchSnapshot(name);
},
);
});