Skip to content

Commit e36ad5a

Browse files
committed
Convert Switch tests to svelte-inline-compile
1 parent bdbc6f4 commit e36ad5a

File tree

1 file changed

+76
-121
lines changed

1 file changed

+76
-121
lines changed

src/lib/components/switch/switch.test.ts

Lines changed: 76 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render } from "@testing-library/svelte";
2-
import TestRenderer from "../../test-utils/TestRenderer.svelte";
32
import { Switch, SwitchDescription, SwitchGroup, SwitchLabel } from ".";
43
import {
54
assertActiveElement,
@@ -15,9 +14,9 @@ jest.mock("../../hooks/use-id");
1514

1615
describe("Safe guards", () => {
1716
it("should be possible to render a Switch without crashing", () => {
18-
render(TestRenderer, {
19-
allProps: [Switch, { checked: false, onChange: console.log }],
20-
});
17+
render(svelte`
18+
<Switch checked={false} on:change={console.log} />
19+
`);
2120
});
2221
});
2322

@@ -43,16 +42,16 @@ describe("Rendering", () => {
4342
})
4443

4544
it("should be possible to render an (on) Switch using an `as` prop", () => {
46-
render(TestRenderer, {
47-
allProps: [Switch, { as: "span", checked: true, onChange: console.log }],
48-
});
45+
render(svelte`
46+
<Switch as={"span"} checked={true} on:change={console.log} />
47+
`);
4948
assertSwitch({ state: SwitchState.On, tag: "span" });
5049
});
5150

5251
it("should be possible to render an (off) Switch using an `as` prop", () => {
53-
render(TestRenderer, {
54-
allProps: [Switch, { as: "span", checked: false, onChange: console.log }],
55-
});
52+
render(svelte`
53+
<Switch as={"span"} checked={false} on:change={console.log} />
54+
`);
5655
assertSwitch({ state: SwitchState.Off, tag: "span" });
5756
});
5857

@@ -67,37 +66,25 @@ describe("Rendering", () => {
6766

6867
describe("`type` attribute", () => {
6968
it('should set the `type` to "button" by default', async () => {
70-
render(TestRenderer, {
71-
allProps: [
72-
Switch,
73-
{ checked: false, onChange: console.log },
74-
"Trigger",
75-
],
76-
});
69+
render(svelte`
70+
<Switch checked={false} on:change={console.log}>Trigger</Switch>
71+
`);
7772

7873
expect(getSwitch()).toHaveAttribute("type", "button");
7974
});
8075

8176
it('should not set the `type` to "button" if it already contains a `type`', async () => {
82-
render(TestRenderer, {
83-
allProps: [
84-
Switch,
85-
{ checked: false, onChange: console.log, type: "submit" },
86-
"Trigger",
87-
],
88-
});
77+
render(svelte`
78+
<Switch checked={false} on:change={console.log} type={"submit"}>Trigger</Switch>
79+
`);
8980

9081
expect(getSwitch()).toHaveAttribute("type", "submit");
9182
});
9283

9384
it('should not set the type if the "as" prop is not a "button"', async () => {
94-
render(TestRenderer, {
95-
allProps: [
96-
Switch,
97-
{ checked: false, onChange: console.log, as: "div" },
98-
"Trigger",
99-
],
100-
});
85+
render(svelte`
86+
<Switch checked={false} on:change={console.log} as={"div"}>Trigger</Switch>
87+
`);
10188

10289
expect(getSwitch()).not.toHaveAttribute("type");
10390
});
@@ -106,31 +93,23 @@ describe("Rendering", () => {
10693

10794
describe("Render composition", () => {
10895
it("should be possible to render a Switch.Group, Switch and Switch.Label", () => {
109-
render(TestRenderer, {
110-
allProps: [
111-
SwitchGroup,
112-
{},
113-
[
114-
[Switch, { checked: false, onChange: console.log }],
115-
[SwitchLabel, {}, "Enable notifications"],
116-
],
117-
],
118-
});
96+
render(svelte`
97+
<SwitchGroup>
98+
<Switch checked={false} on:change={console.log} />
99+
<SwitchLabel>Enable notifications</SwitchLabel>
100+
</SwitchGroup>
101+
`);
119102

120103
assertSwitch({ state: SwitchState.Off, label: "Enable notifications" });
121104
});
122105

123106
it("should be possible to render a Switch.Group, Switch and Switch.Label (before the Switch)", () => {
124-
render(TestRenderer, {
125-
allProps: [
126-
SwitchGroup,
127-
{},
128-
[
129-
[SwitchLabel, {}, "Label B"],
130-
[Switch, { checked: false, onChange: console.log }, "Label A"],
131-
],
132-
],
133-
});
107+
render(svelte`
108+
<SwitchGroup>
109+
<SwitchLabel>Label B</SwitchLabel>
110+
<Switch checked={false} on:change={console.log}>Label A</Switch>
111+
</SwitchGroup>
112+
`);
134113

135114
// Warning! Using aria-label or aria-labelledby will hide any descendant content from assistive
136115
// technologies.
@@ -140,16 +119,12 @@ describe("Render composition", () => {
140119
});
141120

142121
it("should be possible to render a Switch.Group, Switch and Switch.Label (after the Switch)", () => {
143-
render(TestRenderer, {
144-
allProps: [
145-
SwitchGroup,
146-
{},
147-
[
148-
[Switch, { checked: false, onChange: console.log }, "Label A"],
149-
[SwitchLabel, {}, "Label B"],
150-
],
151-
],
152-
});
122+
render(svelte`
123+
<SwitchGroup>
124+
<Switch checked={false} on:change={console.log}>Label A</Switch>
125+
<SwitchLabel>Label B</SwitchLabel>
126+
</SwitchGroup>
127+
`);
153128

154129
// Warning! Using aria-label or aria-labelledby will hide any descendant content from assistive
155130
// technologies.
@@ -159,16 +134,12 @@ describe("Render composition", () => {
159134
});
160135

161136
it("should be possible to render a Switch.Group, Switch and Switch.Description (before the Switch)", async () => {
162-
render(TestRenderer, {
163-
allProps: [
164-
SwitchGroup,
165-
{},
166-
[
167-
[SwitchDescription, {}, "This is an important feature"],
168-
[Switch, { checked: false, onChange: console.log }],
169-
],
170-
],
171-
});
137+
render(svelte`
138+
<SwitchGroup>
139+
<SwitchDescription>This is an important feature</SwitchDescription>
140+
<Switch checked={false} on:change={console.log} />
141+
</SwitchGroup>
142+
`);
172143

173144
assertSwitch({
174145
state: SwitchState.Off,
@@ -177,16 +148,12 @@ describe("Render composition", () => {
177148
});
178149

179150
it("should be possible to render a Switch.Group, Switch and Switch.Description (after the Switch)", () => {
180-
render(TestRenderer, {
181-
allProps: [
182-
SwitchGroup,
183-
{},
184-
[
185-
[Switch, { checked: false, onChange: console.log }],
186-
[SwitchDescription, {}, "This is an important feature"],
187-
],
188-
],
189-
});
151+
render(svelte`
152+
<SwitchGroup>
153+
<Switch checked={false} on:change={console.log} />
154+
<SwitchDescription>This is an important feature</SwitchDescription>
155+
</SwitchGroup>
156+
`);
190157

191158
assertSwitch({
192159
state: SwitchState.Off,
@@ -195,17 +162,13 @@ describe("Render composition", () => {
195162
});
196163

197164
it("should be possible to render a Switch.Group, Switch, Switch.Label and Switch.Description", () => {
198-
render(TestRenderer, {
199-
allProps: [
200-
SwitchGroup,
201-
{},
202-
[
203-
[SwitchLabel, {}, "Label A"],
204-
[Switch, { checked: false, onChange: console.log }],
205-
[SwitchDescription, {}, "This is an important feature"],
206-
],
207-
],
208-
});
165+
render(svelte`
166+
<SwitchGroup>
167+
<SwitchLabel>Label A</SwitchLabel>
168+
<Switch checked={false} on:change={console.log} />
169+
<SwitchDescription>This is an important feature</SwitchDescription>
170+
</SwitchGroup>
171+
`);
209172

210173
assertSwitch({
211174
state: SwitchState.Off,
@@ -218,9 +181,9 @@ describe("Render composition", () => {
218181
describe("Keyboard interactions", () => {
219182
describe("`Space` key", () => {
220183
it("should be possible to toggle the Switch with Space", async () => {
221-
render(TestRenderer, {
222-
allProps: [ManagedSwitch, {}],
223-
});
184+
render(svelte`
185+
<ManagedSwitch />
186+
`);
224187

225188
// Ensure checkbox is off
226189
assertSwitch({ state: SwitchState.Off });
@@ -245,9 +208,9 @@ describe("Keyboard interactions", () => {
245208
describe("`Enter` key", () => {
246209
it("should not be possible to use Enter to toggle the Switch", async () => {
247210
let handleChange = jest.fn();
248-
render(TestRenderer, {
249-
allProps: [ManagedSwitch, { onChange: handleChange }],
250-
});
211+
render(svelte`
212+
<ManagedSwitch onChange={handleChange}/>
213+
`);
251214

252215
// Ensure checkbox is off
253216
assertSwitch({ state: SwitchState.Off });
@@ -291,9 +254,9 @@ describe("Keyboard interactions", () => {
291254

292255
describe("Mouse interactions", () => {
293256
it("should be possible to toggle the Switch with a click", async () => {
294-
render(TestRenderer, {
295-
allProps: [ManagedSwitch, {}],
296-
});
257+
render(svelte`
258+
<ManagedSwitch />
259+
`);
297260

298261
// Ensure checkbox is off
299262
assertSwitch({ state: SwitchState.Off });
@@ -312,16 +275,12 @@ describe("Mouse interactions", () => {
312275
});
313276

314277
it("should be possible to toggle the Switch with a click on the Label", async () => {
315-
render(TestRenderer, {
316-
allProps: [
317-
SwitchGroup,
318-
{},
319-
[
320-
[ManagedSwitch, {}],
321-
[SwitchLabel, {}, "The label"],
322-
],
323-
],
324-
});
278+
render(svelte`
279+
<SwitchGroup>
280+
<ManagedSwitch />
281+
<SwitchLabel>The label</SwitchLabel>
282+
</SwitchGroup>
283+
`);
325284

326285
// Ensure checkbox is off
327286
assertSwitch({ state: SwitchState.Off });
@@ -346,16 +305,12 @@ describe("Mouse interactions", () => {
346305
});
347306

348307
it("should not be possible to toggle the Switch with a click on the Label (passive)", async () => {
349-
render(TestRenderer, {
350-
allProps: [
351-
SwitchGroup,
352-
{},
353-
[
354-
[ManagedSwitch, {}],
355-
[SwitchLabel, { passive: true }, "The label"],
356-
],
357-
],
358-
});
308+
render(svelte`
309+
<SwitchGroup>
310+
<ManagedSwitch />
311+
<SwitchLabel passive={true}>The label</SwitchLabel>
312+
</SwitchGroup>
313+
`);
359314

360315
// Ensure checkbox is off
361316
assertSwitch({ state: SwitchState.Off });

0 commit comments

Comments
 (0)