Skip to content

Commit cb4655d

Browse files
committed
test: add test for Q8
1 parent e4ca495 commit cb4655d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

questions/8-effect-scope/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const doubled = computed(() => counter.value * 2)
77
// use the `effectScope` API to make these effects stop together after being triggered once
88
99
watch(doubled, () => console.log(doubled.value))
10-
watchEffect(() => console.log("Count: ", doubled.value))
10+
watchEffect(() => console.log(`Count: ${doubled.value}`))
1111
1212
counter.value = 2
1313
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mount } from "@vue/test-utils"
2+
import { describe, it, expect, vi } from "vitest"
3+
4+
import App from "./App.vue"
5+
6+
function delay(timeout: number) {
7+
return new Promise((resolve) => {
8+
setTimeout(resolve, timeout)
9+
})
10+
}
11+
12+
describe("EffectScope", () => {
13+
it("should work", async() => {
14+
const result: string[] = []
15+
console.log = vi.fn((log: string) => {
16+
result.push(log)
17+
})
18+
mount(App)
19+
await delay(1000)
20+
expect(JSON.stringify(result)).toBe(JSON.stringify([
21+
"Count: 2", 4, "Count: 4",
22+
]))
23+
})
24+
})

0 commit comments

Comments
 (0)