Skip to content

Commit 2b4eac0

Browse files
committed
chore: add test for reactivity with template literals
1 parent abc7732 commit 2b4eac0

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

packages/qwik/src/core/tests/component.spec.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,64 @@ describe.each([
21622162
);
21632163
});
21642164

2165+
it('#6585 - reactivity should work with template literals', async () => {
2166+
const Cmp = component$(() => {
2167+
const useFoo = (count: SignalType<number>) => {
2168+
const tag = (s: string | TemplateStringsArray) => {
2169+
const value = typeof s === 'string' ? s : s[0];
2170+
return `${value}-${count.value}`;
2171+
};
2172+
return tag;
2173+
};
2174+
const count = useSignal(0);
2175+
const foo = useFoo(count);
2176+
return (
2177+
<>
2178+
<p>{foo('test')}</p>
2179+
<p>{foo`test`}</p>
2180+
<button
2181+
onClick$={() => {
2182+
count.value++;
2183+
}}
2184+
>
2185+
Count up
2186+
</button>
2187+
</>
2188+
);
2189+
});
2190+
2191+
const { vNode, document } = await render(<Cmp />, { debug });
2192+
expect(vNode).toMatchVDOM(
2193+
<Component ssr-required>
2194+
<Fragment ssr-required>
2195+
<p>test-0</p>
2196+
<p>test-0</p>
2197+
<button>Count up</button>
2198+
</Fragment>
2199+
</Component>
2200+
);
2201+
await trigger(document.body, 'button', 'click');
2202+
expect(vNode).toMatchVDOM(
2203+
<Component ssr-required>
2204+
<Fragment ssr-required>
2205+
<p>test-1</p>
2206+
<p>test-1</p>
2207+
<button>Count up</button>
2208+
</Fragment>
2209+
</Component>
2210+
);
2211+
await trigger(document.body, 'button', 'click');
2212+
expect(vNode).toMatchVDOM(
2213+
<Component ssr-required>
2214+
<Fragment ssr-required>
2215+
<p>test-2</p>
2216+
<p>test-2</p>
2217+
<button>Count up</button>
2218+
</Fragment>
2219+
</Component>
2220+
);
2221+
});
2222+
21652223
it('#7203 - should correctly move found vnode', async () => {
21662224
const Cmp = component$(() => {
21672225
const type = useSignal<'A' | 'B' | 'C'>('B');

0 commit comments

Comments
 (0)