Skip to content

Commit 8da5dac

Browse files
committed
test: unused describe()
1 parent bbade5e commit 8da5dac

File tree

1 file changed

+95
-97
lines changed

1 file changed

+95
-97
lines changed

tests/computedArray.spec.ts

Lines changed: 95 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,112 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { expect, test, vi } from 'vitest';
22
import { effect, signal } from '..';
33
import { computedArray } from '../unstable/computedArray';
44

5-
describe('computedArray', () => {
6-
it('should get updated item value', () => {
7-
const src = signal([1]);
8-
const arr = computedArray(src, item => {
9-
return () => item.get() + 1;
10-
});
11-
expect(arr[0]).toBe(2);
5+
test('should get updated item value', () => {
6+
const src = signal([1]);
7+
const arr = computedArray(src, item => {
8+
return () => item.get() + 1;
129
});
10+
expect(arr[0]).toBe(2);
11+
});
1312

14-
it('should watch item value change', () => {
15-
const spy = vi.fn();
16-
const src = signal([1]);
17-
const arr = computedArray(src, item => {
18-
return () => item.get() + 1;
19-
});
20-
effect(() => {
21-
spy();
22-
arr[0];
23-
});
24-
expect(spy).toHaveBeenCalledTimes(1);
25-
src.set([2]);
26-
expect(spy).toHaveBeenCalledTimes(2);
13+
test('should watch item value change', () => {
14+
const spy = vi.fn();
15+
const src = signal([1]);
16+
const arr = computedArray(src, item => {
17+
return () => item.get() + 1;
18+
});
19+
effect(() => {
20+
spy();
21+
arr[0];
2722
});
23+
expect(spy).toHaveBeenCalledTimes(1);
24+
src.set([2]);
25+
expect(spy).toHaveBeenCalledTimes(2);
26+
});
2827

29-
it('should not trigger if item value did not change', () => {
30-
const spy = vi.fn();
31-
const src = signal([1]);
32-
const arr = computedArray(src, item => {
33-
return () => item.get() + 1;
34-
});
35-
effect(() => {
36-
spy();
37-
arr[0];
38-
});
39-
expect(spy).toHaveBeenCalledTimes(1);
40-
src.set([1]);
41-
expect(spy).toHaveBeenCalledTimes(1);
28+
test('should not trigger if item value did not change', () => {
29+
const spy = vi.fn();
30+
const src = signal([1]);
31+
const arr = computedArray(src, item => {
32+
return () => item.get() + 1;
33+
});
34+
effect(() => {
35+
spy();
36+
arr[0];
37+
});
38+
expect(spy).toHaveBeenCalledTimes(1);
39+
src.set([1]);
40+
expect(spy).toHaveBeenCalledTimes(1);
41+
});
42+
43+
test('should not trigger first item computed if source item did not change', () => {
44+
const spy = vi.fn();
45+
const src = signal([1]);
46+
const arr = computedArray(src, (item, i) => {
47+
return () => {
48+
if (i === 0) {
49+
spy();
50+
}
51+
return item.get() + 1;
52+
};
4253
});
54+
effect(() => arr[0]);
55+
expect(spy).toHaveBeenCalledTimes(1);
56+
src.set([1, 2]);
57+
expect(spy).toHaveBeenCalledTimes(1);
58+
src.set([2, 2, 3]);
59+
expect(spy).toHaveBeenCalledTimes(2);
60+
});
4361

44-
it('should not trigger first item computed if source item did not change', () => {
45-
const spy = vi.fn();
46-
const src = signal([1]);
47-
const arr = computedArray(src, (item, i) => {
48-
return () => {
49-
if (i === 0) {
50-
spy();
51-
}
52-
return item.get() + 1;
53-
};
54-
});
55-
effect(() => arr[0]);
56-
expect(spy).toHaveBeenCalledTimes(1);
57-
src.set([1, 2]);
58-
expect(spy).toHaveBeenCalledTimes(1);
59-
src.set([2, 2, 3]);
60-
expect(spy).toHaveBeenCalledTimes(2);
62+
test('should watch length change', () => {
63+
const spy = vi.fn();
64+
const src = signal([1]);
65+
const arr = computedArray(src, item => {
66+
return () => item.get() + 1;
67+
});
68+
effect(() => {
69+
spy();
70+
arr.length;
6171
});
72+
expect(spy).toHaveBeenCalledTimes(1);
73+
src.set([2]);
74+
expect(spy).toHaveBeenCalledTimes(1);
75+
src.set([2, 3]);
76+
expect(spy).toHaveBeenCalledTimes(2);
77+
});
6278

63-
it('should watch length change', () => {
64-
const spy = vi.fn();
65-
const src = signal([1]);
66-
const arr = computedArray(src, item => {
67-
return () => item.get() + 1;
68-
});
69-
effect(() => {
70-
spy();
71-
arr.length;
72-
});
73-
expect(spy).toHaveBeenCalledTimes(1);
74-
src.set([2]);
75-
expect(spy).toHaveBeenCalledTimes(1);
76-
src.set([2, 3]);
77-
expect(spy).toHaveBeenCalledTimes(2);
79+
test('should watch item remove', () => {
80+
const spy = vi.fn();
81+
const src = signal([1, 2]);
82+
const arr = computedArray(src, item => {
83+
return () => item.get() + 1;
7884
});
85+
effect(() => {
86+
spy();
87+
arr[0];
88+
});
89+
expect(spy).toHaveBeenCalledTimes(1);
90+
src.set([1]);
91+
expect(spy).toHaveBeenCalledTimes(1);
92+
src.set([]);
93+
expect(spy).toHaveBeenCalledTimes(2);
94+
});
7995

80-
it('should watch item remove', () => {
81-
const spy = vi.fn();
82-
const src = signal([1, 2]);
83-
const arr = computedArray(src, item => {
84-
return () => item.get() + 1;
85-
});
86-
effect(() => {
96+
test('should only trigger access items', () => {
97+
const spy = vi.fn();
98+
const src = signal([1, 2, 3, 4]);
99+
const arr = computedArray(src, item => {
100+
return () => {
87101
spy();
88-
arr[0];
89-
});
90-
expect(spy).toHaveBeenCalledTimes(1);
91-
src.set([1]);
92-
expect(spy).toHaveBeenCalledTimes(1);
93-
src.set([]);
94-
expect(spy).toHaveBeenCalledTimes(2);
102+
return item.get() + 1;
103+
};
95104
});
96-
97-
it('should only trigger access items', () => {
98-
const spy = vi.fn();
99-
const src = signal([1, 2, 3, 4]);
100-
const arr = computedArray(src, item => {
101-
return () => {
102-
spy();
103-
return item.get() + 1;
104-
};
105-
});
106-
effect(() => {
107-
arr[0];
108-
arr[1];
109-
});
110-
expect(spy).toHaveBeenCalledTimes(2);
111-
src.set([2, 3, 4, 5]);
112-
expect(spy).toHaveBeenCalledTimes(4);
105+
effect(() => {
106+
arr[0];
107+
arr[1];
113108
});
109+
expect(spy).toHaveBeenCalledTimes(2);
110+
src.set([2, 3, 4, 5]);
111+
expect(spy).toHaveBeenCalledTimes(4);
114112
});

0 commit comments

Comments
 (0)