-
Notifications
You must be signed in to change notification settings - Fork 0
/
useCounter.test.ts
81 lines (57 loc) · 1.52 KB
/
useCounter.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { get } from "svelte/store";
import { useCounter } from "@/hooks";
describe("Hooks - useCounter", () => {
test("value 0 by default", () => {
const { count } = useCounter(0);
expect(get(count)).toBe(0);
});
test("increment value", () => {
const { count, increment } = useCounter(0);
increment();
expect(get(count)).toBe(1);
});
test("decrement value", () => {
const { count, decrement } = useCounter(0);
decrement();
expect(get(count)).toBe(-1);
});
test("increment value to 3", () => {
const { count, increment } = useCounter(0);
increment(3);
expect(get(count)).toBe(3);
});
test("decrement value to 3", () => {
const { count, decrement } = useCounter(0);
decrement(3);
expect(get(count)).toBe(-3);
});
test("reset value", () => {
const { count, increment, reset } = useCounter(0);
increment(3);
reset();
expect(get(count)).toBe(0);
});
test("set specific value", () => {
const { count, setCount } = useCounter(0);
setCount(100);
expect(get(count)).toBe(100);
});
test("on MouseEvent, should increment 1 by default", () => {
const { count, increment } = useCounter(0);
const event = new MouseEvent("click", {
bubbles: true,
cancelable: true,
});
increment(event);
expect(get(count)).toBe(1);
});
test("on MouseEvent, should decrement 1 by default", () => {
const { count, decrement } = useCounter(0);
const event = new MouseEvent("click", {
bubbles: true,
cancelable: true,
});
decrement(event);
expect(get(count)).toBe(-1);
});
});