Skip to content

Commit b23cfe0

Browse files
committed
test: overrideProps snapshot
1 parent e16695d commit b23cfe0

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

packages/babel-plugin-jsx/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type State = {
1111
opts: Opts;
1212
}
1313

14-
interface Opts {
14+
export interface Opts {
1515
transformOn?: boolean;
1616
optimize?: boolean;
1717
mergeProps?: boolean;

packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ withDirectives(createVNode(\\"input\\", {
7979
}, null, 8, [\\"onUpdate:modelValue\\"]), [[vModelText, test]]);"
8080
`;
8181

82+
exports[`override props multiple: multiple 1`] = `
83+
"import { resolveComponent, createVNode } from \\"vue\\";
84+
createVNode(resolveComponent(\\"A\\"), {
85+
\\"loading\\": true,
86+
...a,
87+
\\"class\\": \\"x\\",
88+
\\"style\\": x
89+
}, null);"
90+
`;
91+
92+
exports[`override props single: single 1`] = `
93+
"import { createVNode } from \\"vue\\";
94+
createVNode(\\"div\\", a, null);"
95+
`;
96+
8297
exports[`reassign variable as component: reassign variable as component 1`] = `
8398
"import { defineComponent, createVNode } from \\"vue\\";
8499
let a = 1;

packages/babel-plugin-jsx/test/snapshot.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { transform } from '@babel/core';
2-
import JSX from '../src';
2+
import JSX, { Opts } from '../src';
33

4-
const transpile = (source: string) => new Promise((resolve, reject) => transform(
4+
const transpile = (
5+
source: string, options: Opts = {},
6+
) => new Promise((resolve, reject) => transform(
57
source,
68
{
79
filename: '',
810
presets: null,
9-
plugins: [[JSX, { optimize: true }]],
11+
plugins: [[JSX, options]],
1012
configFile: false,
1113
}, (error, result) => {
1214
if (error) {
@@ -138,7 +140,26 @@ tests.forEach((
138140
test(
139141
name,
140142
async () => {
141-
expect(await transpile(from)).toMatchSnapshot(name);
143+
expect(await transpile(from, { optimize: true })).toMatchSnapshot(name);
144+
},
145+
);
146+
});
147+
148+
const overridePropsTests = [{
149+
name: 'single',
150+
from: '<div {...a}></div>',
151+
}, {
152+
name: 'multiple',
153+
from: '<A loading {...a} class="x" style={x}></A>',
154+
}];
155+
156+
overridePropsTests.forEach((
157+
{ name, from },
158+
) => {
159+
test(
160+
`override props ${name}`,
161+
async () => {
162+
expect(await transpile(from, { mergeProps: false })).toMatchSnapshot(name);
142163
},
143164
);
144165
});

0 commit comments

Comments
 (0)