Skip to content

Commit a36ec12

Browse files
committed
Add tests for useNativeSpread
1 parent 4c63b41 commit a36ec12

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/babel.test.mjs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ describe('htm/babel', () => {
4646
]
4747
}).code
4848
).toBe(`h("a",Object.assign({b:2},{c:3}),"d: ",4);`);
49+
50+
expect(
51+
transform('html`<a b=${2} ...${{ c: 3 }}>d: ${4}</a>`;', {
52+
...options,
53+
plugins: [
54+
[htmBabelPlugin, {
55+
useNativeSpread: true
56+
}]
57+
]
58+
}).code
59+
).toBe(`h("a",{b:2,...{c:3}},"d: ",4);`);
4960
});
5061

5162
test('spread a single variable', () => {
@@ -57,6 +68,17 @@ describe('htm/babel', () => {
5768
]
5869
}).code
5970
).toBe(`h("a",foo);`);
71+
72+
expect(
73+
transform('html`<a ...${foo}></a>`;', {
74+
...options,
75+
plugins: [
76+
[htmBabelPlugin, {
77+
useNativeSpread: true
78+
}]
79+
]
80+
}).code
81+
).toBe(`h("a",foo);`);
6082
});
6183

6284
test('spread two variables', () => {
@@ -70,6 +92,17 @@ describe('htm/babel', () => {
7092
]
7193
}).code
7294
).toBe(`h("a",Object.assign({},foo,bar));`);
95+
96+
expect(
97+
transform('html`<a ...${foo} ...${bar}></a>`;', {
98+
...options,
99+
plugins: [
100+
[htmBabelPlugin, {
101+
useNativeSpread: true
102+
}]
103+
]
104+
}).code
105+
).toBe(`h("a",{...foo,...bar});`);
73106
});
74107

75108
test('property followed by a spread', () => {
@@ -83,6 +116,17 @@ describe('htm/babel', () => {
83116
]
84117
}).code
85118
).toBe(`h("a",Object.assign({b:"1"},foo));`);
119+
120+
expect(
121+
transform('html`<a b="1" ...${foo}></a>`;', {
122+
...options,
123+
plugins: [
124+
[htmBabelPlugin, {
125+
useNativeSpread: true
126+
}]
127+
]
128+
}).code
129+
).toBe(`h("a",{b:"1",...foo});`);
86130
});
87131

88132
test('spread followed by a property', () => {
@@ -96,6 +140,17 @@ describe('htm/babel', () => {
96140
]
97141
}).code
98142
).toBe(`h("a",Object.assign({},foo,{b:"1"}));`);
143+
144+
expect(
145+
transform('html`<a ...${foo} b="1"></a>`;', {
146+
...options,
147+
plugins: [
148+
[htmBabelPlugin, {
149+
useNativeSpread: true
150+
}]
151+
]
152+
}).code
153+
).toBe(`h("a",{...foo,b:"1"});`);
99154
});
100155

101156
test('mix-and-match spreads', () => {
@@ -109,6 +164,17 @@ describe('htm/babel', () => {
109164
]
110165
}).code
111166
).toBe(`h("a",Object.assign({b:"1"},foo,{c:2},{d:3}));`);
167+
168+
expect(
169+
transform('html`<a b="1" ...${foo} c=${2} ...${{d:3}}></a>`;', {
170+
...options,
171+
plugins: [
172+
[htmBabelPlugin, {
173+
useNativeSpread: true
174+
}]
175+
]
176+
}).code
177+
).toBe(`h("a",{b:"1",...foo,c:2,...{d:3}});`);
112178
});
113179

114180
describe('{variableArity:false}', () => {

0 commit comments

Comments
 (0)