Skip to content

Commit 31dff45

Browse files
committed
Simplify list tests
1 parent a078767 commit 31dff45

File tree

1 file changed

+13
-93
lines changed

1 file changed

+13
-93
lines changed

packages/list/test/index.test.tsx

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,11 @@ describe("listArray", () => {
3131
describe("List", () => {
3232
test("simple", () => {
3333
const container = document.createElement("div");
34-
document.body.appendChild(container);
3534

3635
const startingArray = [1, 2, 3, 4];
3736
const [s] = createSignal(startingArray);
3837
const unmount = render(
39-
() => (
40-
<List each={s()}>
41-
{(v, i) => (
42-
<div>
43-
{i()}: {v() * 2}
44-
</div>
45-
)}
46-
</List>
47-
),
38+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
4839
container,
4940
);
5041

@@ -53,25 +44,15 @@ describe("List", () => {
5344
});
5445

5546
unmount();
56-
document.body.removeChild(container);
5747
});
5848

5949
test("doesn't change for same values", () => {
6050
const container = document.createElement("div");
61-
document.body.appendChild(container);
6251

6352
const startingArray = [1, 2, 3, 4];
6453
const [s, set] = createSignal(startingArray);
6554
const unmount = render(
66-
() => (
67-
<List each={s()}>
68-
{(v, i) => (
69-
<div>
70-
{i()}: {v() * 2}
71-
</div>
72-
)}
73-
</List>
74-
),
55+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
7556
container,
7657
);
7758

@@ -89,25 +70,15 @@ describe("List", () => {
8970
});
9071

9172
unmount();
92-
document.body.removeChild(container);
9373
});
9474

9575
test("reorders elements", () => {
9676
const container = document.createElement("div");
97-
document.body.appendChild(container);
9877

9978
const startingArray = [1, 2, 3, 4];
10079
const [s, set] = createSignal(startingArray);
10180
const unmount = render(
102-
() => (
103-
<List each={s()}>
104-
{(v, i) => (
105-
<div>
106-
{i()}: {v() * 2}
107-
</div>
108-
)}
109-
</List>
110-
),
81+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
11182
container,
11283
);
11384

@@ -132,25 +103,15 @@ describe("List", () => {
132103
expect(oldMapped[3]).toBe(newMapped[3]);
133104

134105
unmount();
135-
document.body.removeChild(container);
136106
});
137107

138108
test("changes value of elements", () => {
139109
const container = document.createElement("div");
140-
document.body.appendChild(container);
141110

142111
const startingArray = [1, 2, 3, 4];
143112
const [s, set] = createSignal(startingArray);
144113
const unmount = render(
145-
() => (
146-
<List each={s()}>
147-
{(v, i) => (
148-
<div>
149-
{i()}: {v() * 2}
150-
</div>
151-
)}
152-
</List>
153-
),
114+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
154115
container,
155116
);
156117

@@ -169,25 +130,15 @@ describe("List", () => {
169130
});
170131

171132
unmount();
172-
document.body.removeChild(container);
173133
});
174134

175135
test("reorders elements with value change", () => {
176136
const container = document.createElement("div");
177-
document.body.appendChild(container);
178137

179138
const startingArray = [1, 2, 3, 4];
180139
const [s, set] = createSignal(startingArray);
181140
const unmount = render(
182-
() => (
183-
<List each={s()}>
184-
{(v, i) => (
185-
<div>
186-
{i()}: {v() * 2}
187-
</div>
188-
)}
189-
</List>
190-
),
141+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
191142
container,
192143
);
193144

@@ -212,25 +163,15 @@ describe("List", () => {
212163
expect(oldMapped[3]).toBe(newMapped[2]);
213164

214165
unmount();
215-
document.body.removeChild(container);
216166
});
217167

218168
test("creates new elements", () => {
219169
const container = document.createElement("div");
220-
document.body.appendChild(container);
221170

222171
const startingArray = [1, 2, 3, 4];
223172
const [s, set] = createSignal(startingArray);
224173
const unmount = render(
225-
() => (
226-
<List each={s()}>
227-
{(v, i) => (
228-
<div>
229-
{i()}: {v() * 2}
230-
</div>
231-
)}
232-
</List>
233-
),
174+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
234175
container,
235176
);
236177

@@ -257,25 +198,15 @@ describe("List", () => {
257198
expect(oldMapped.includes(newMapped[3]!)).toEqual(false);
258199

259200
unmount();
260-
document.body.removeChild(container);
261201
});
262202

263203
test("deletes unused elements", () => {
264204
const container = document.createElement("div");
265-
document.body.appendChild(container);
266205

267206
const startingArray = [1, 2, 3, 4];
268207
const [s, set] = createSignal(startingArray);
269208
const unmount = render(
270-
() => (
271-
<List each={s()}>
272-
{(v, i) => (
273-
<div>
274-
{i()}: {v() * 2}
275-
</div>
276-
)}
277-
</List>
278-
),
209+
() => <List each={s()}>{(v, i) => <div>{i()}: {v() * 2}</div>}</List>,
279210
container,
280211
);
281212

@@ -300,32 +231,22 @@ describe("List", () => {
300231
expect(newMapped.includes(oldMapped[2]!)).toEqual(false);
301232

302233
unmount();
303-
document.body.removeChild(container);
304234
});
305235

306236
test("later used signal reports correct values", () => {
307237
const container = document.createElement("div");
308-
document.body.appendChild(container);
309238

310239
const startingArray = [1, 2, 3];
311240
const [s, set] = createSignal(startingArray);
312241
const callbacks: (() => { v: number; i: number })[] = [];
313242
const unmount = render(
314243
() => (
315-
<List each={s()}>
316-
{(v, i) => {
317-
// this could be event callback (eg. onClick), v & i read only later
318-
function futureAction() {
319-
return {
320-
v: v(),
321-
i: i(),
322-
};
323-
}
324-
callbacks.push(() => futureAction());
325-
326-
return <div>No signals used in this fn</div>;
327-
}}
328-
</List>
244+
<List each={s()}>{(v, i) => {
245+
// this could be event callback (eg. onClick), v & i read only later
246+
callbacks.push(() => ({ v: v(), i: i() }))
247+
248+
return null
249+
}}</List>
329250
),
330251
container,
331252
);
@@ -341,6 +262,5 @@ describe("List", () => {
341262
expect(values).toStrictEqual([2, 1, 4]);
342263

343264
unmount();
344-
document.body.removeChild(container);
345265
});
346266
});

0 commit comments

Comments
 (0)