File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
questions/11-next-dom-update Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 2
2
import { ref } from " vue"
3
3
4
4
const count = ref (0 )
5
+ const counter = ref (null )
5
6
6
7
function increment () {
7
8
count .value ++
@@ -10,13 +11,12 @@ function increment() {
10
11
* DOM is not yet updated, how can we make sure that the DOM gets updated
11
12
* Make the output be true
12
13
*/
13
-
14
- console .log (+ document .getElementById (" counter" ).textContent === 1 )
14
+ console .log (+ counter .value .textContent === 1 )
15
15
}
16
16
</script >
17
17
18
18
<template >
19
- <button id =" counter" @click =" increment" >
19
+ <button ref =" counter" @click =" increment" >
20
20
{{ count }}
21
21
</button >
22
22
</template >
Original file line number Diff line number Diff line change
1
+ import { mount } from "@vue/test-utils"
2
+ import { describe , it , expect , vi } from "vitest"
3
+
4
+ import App from "./App.vue"
5
+
6
+ describe ( "next-dom-update" , ( ) => {
7
+ it ( "should work'" , async ( ) => {
8
+ let printLog = ''
9
+ console . log = vi . fn (
10
+ ( log : string ) => {
11
+ printLog = log ?. toString ( ) ?. trim ( )
12
+ } )
13
+ const wrapper = mount ( App )
14
+
15
+ expect ( wrapper . text ( ) ) . toMatchInlineSnapshot ( "\"0\"" )
16
+
17
+ const button = wrapper . find ( "button" )
18
+ await button . trigger ( "click" )
19
+
20
+ expect ( wrapper . text ( ) ) . toMatchInlineSnapshot ( '"1"' )
21
+ expect ( printLog ) . toMatchInlineSnapshot ( '"true"' )
22
+ } )
23
+ } )
You can’t perform that action at this time.
0 commit comments