mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
test: overrideProps snapshot
This commit is contained in:
parent
e16695d87e
commit
b23cfe0020
@ -11,7 +11,7 @@ export type State = {
|
||||
opts: Opts;
|
||||
}
|
||||
|
||||
interface Opts {
|
||||
export interface Opts {
|
||||
transformOn?: boolean;
|
||||
optimize?: boolean;
|
||||
mergeProps?: boolean;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user