Skip to content

Commit 0ccb2c9

Browse files
committed
Simplify update element test.
1 parent 20e7a9d commit 0ccb2c9

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

test/app.test.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,47 +67,3 @@ test("optional view", done => {
6767
}
6868
})
6969
})
70-
71-
test("view values update upon state change", done => {
72-
document.body.innerHTML = `<div id="app"></div>`
73-
const emit = app({
74-
root: document.getElementById("app"),
75-
state: { changeInput: false },
76-
view: state => h("input", { id: state.changeInput ? "foo" : "bar", "value" : state.changeInput ? "fizz" : "buzz" }),
77-
actions: {
78-
updateInput (app, state, actions) {
79-
state.changeInput = true
80-
return state
81-
}
82-
},
83-
events: {
84-
updateView (state, actions) {
85-
actions.updateInput()
86-
},
87-
load () {
88-
expect(document.body.innerHTML).toBe(
89-
`<div id="app"></div>`
90-
)
91-
}
92-
}
93-
})
94-
95-
const firstRenderId = requestAnimationFrame(() => {
96-
expect(document.body.innerHTML).toBe(
97-
`<input id="bar" value="buzz">`
98-
)
99-
100-
emit("updateView")
101-
102-
const secondRenderId = requestAnimationFrame(() => {
103-
console.log(document.body.innerHTML)
104-
expect(document.body.innerHTML).toBe(
105-
`<input id="foo" value="fizz">`
106-
)
107-
done()
108-
cancelAnimationFrame(secondRenderId)
109-
})
110-
111-
cancelAnimationFrame(firstRenderId)
112-
})
113-
})

test/vdom.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,26 @@ testTrees("skip setAttribute for functions", [
653653
html: `<div></div>`
654654
}
655655
])
656+
657+
testTrees("update element with dynamic props", [
658+
{
659+
tree: h("input", {
660+
type: "text",
661+
oncreate(element) {
662+
element.value = "bar"
663+
},
664+
value: "foo"
665+
}),
666+
html: `<input type="text" value="foo">`
667+
},
668+
{
669+
tree: h("input", {
670+
type: "text",
671+
onupdate(element) {
672+
expect(element.value).toBe("foo")
673+
},
674+
value: "foo"
675+
}),
676+
html: `<input type="text" value="foo">`
677+
}
678+
])

0 commit comments

Comments
 (0)