Skip to content

Commit 416482f

Browse files
committed
feat(timer mocks): example with timermocks
1 parent ddba46c commit 416482f

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/components/bohnen/BohnenRow.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("BohnenRow", () => {
4747
});
4848
});
4949

50-
it.skip("should dispatch an UPDATE event if the user updates the EKP fake timers", async () => {
50+
it("should dispatch an UPDATE event if the user updates the EKP fake timers", async () => {
5151
vitest.useFakeTimers();
5252

5353
const mockBohne = getMockBohne();
@@ -62,14 +62,13 @@ describe("BohnenRow", () => {
6262

6363
fireEvent.change(input, {
6464
target: {
65-
value: "12",
65+
value: "15",
6666
},
6767
});
68-
vitest.advanceTimersByTime(500);
69-
68+
vitest.advanceTimersByTime(1000);
7069
expect(dispatchMock).toHaveBeenCalledWith({
7170
type: "UPDATE",
72-
payload: { ...mockBohne, ekp: 12 },
71+
payload: { ...mockBohne, ekp: 15 },
7372
});
7473
vitest.useRealTimers();
7574
});
@@ -87,13 +86,15 @@ describe("BohnenRow", () => {
8786

8887
fireEvent.change(input, {
8988
target: {
90-
value: "12",
89+
value: "15",
9190
},
9291
});
9392

93+
await new Promise((resolve) => setTimeout(resolve, 2000));
94+
9495
expect(dispatchMock).toHaveBeenCalledWith({
9596
type: "UPDATE",
96-
payload: { ...mockBohne, ekp: 12 },
97+
payload: { ...mockBohne, ekp: 15 },
9798
});
9899
});
99100
});

src/components/bohnen/BohnenRow.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const BohnenRow = ({ bohne }: BohnenRowProps) => {
1717
clearTimeout(debounceTimeout.current);
1818
}
1919
debounceTimeout.current = setTimeout(() => {
20-
console.log("da isser");
2120
dispatch(action);
2221
}, 1000);
2322
},
@@ -28,7 +27,6 @@ const BohnenRow = ({ bohne }: BohnenRowProps) => {
2827
"w-full border-1 border-slate-400 p-1 outline-1 outline-transparent focus:border-cyan-600 focus:outline-1 focus:outline-cyan-600 disabled:bg-slate-200";
2928

3029
const numberInputClasses = `${inputClasses} text-right font-mono`;
31-
3230
return (
3331
<tr key={bohne.id}>
3432
<td>
@@ -53,7 +51,6 @@ const BohnenRow = ({ bohne }: BohnenRowProps) => {
5351
aria-label="EKP"
5452
className={numberInputClasses}
5553
onChange={(event) => {
56-
console.log("Changedichange", event.target.value);
5754
debouncedDispatch({
5855
type: BohnenActionTypes.UPDATE,
5956
payload: {
@@ -69,17 +66,9 @@ const BohnenRow = ({ bohne }: BohnenRowProps) => {
6966
<input
7067
type="number"
7168
data-testid="marge"
69+
aria-label="MARGE"
7270
className={numberInputClasses}
7371
disabled={true}
74-
onChange={(event) =>
75-
debouncedDispatch({
76-
type: BohnenActionTypes.UPDATE,
77-
payload: {
78-
...bohne,
79-
marge: parseFloat(event.target.value),
80-
},
81-
})
82-
}
8372
value={bohne.marge || ""}
8473
/>
8574
</td>
@@ -105,6 +94,7 @@ const BohnenRow = ({ bohne }: BohnenRowProps) => {
10594
type="number"
10695
id="vkp"
10796
data-testid="vkp"
97+
aria-label="VKP"
10898
className={numberInputClasses}
10999
onChange={(event) =>
110100
debouncedDispatch({

0 commit comments

Comments
 (0)