-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypp_test.go
More file actions
107 lines (90 loc) · 3.21 KB
/
hypp_test.go
File metadata and controls
107 lines (90 loc) · 3.21 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package hypp
import (
"testing"
"github.com/stretchr/testify/assert"
)
// This test is based on https://github.com/jorgebucaran/hyperapp/blob/8e6a4908954186ed8466ae9ef15ec172ddbea2d0/tests/index.test.js#L7
func TestCreateVirtualNode(t *testing.T) {
assert.Equal(t, &VNode{
props: HProps{"foo": true},
tag: "zord",
kind: 1,
}, H("zord", HProps{"foo": true}))
}
// This test is based on https://github.com/jorgebucaran/hyperapp/blob/8e6a4908954186ed8466ae9ef15ec172ddbea2d0/tests/index.test.js#L20
func TestCreateTextNode(t *testing.T) {
assert.Equal(t, &VNode{
tag: "hyper",
kind: 3,
}, Text("hyper"))
}
func TestSetValueOnNilHProps(t *testing.T) {
var props HProps
props.Set("foo", "bar")
assert.Equal(t, HProps{"foo": "bar"}, props)
}
// TestKeepKeyOnVNodeShallowClone should ensure that the key of a VNode is kept when performing a shallow clone.
//
// The following hyperapp pull request contains "a small improvement regarding how keys are handled": https://github.com/jorgebucaran/hyperapp/pull/1090
// This change removes "key" from the HProps when creating a VNode.
// Similar changes were made to hypp: https://github.com/macabot/hypp/pull/26
// The problem, however, was that a shallow clone of a VNode no longer contained the key.
func TestKeepKeyOnVNodeShallowClone(t *testing.T) {
span := H("span", HProps{"key": "foo"}, Text("test"))
shallowClone := func(n *VNode) *VNode {
return H(n.Tag(), n.Props(), n.Children()...)
}
spanClone := shallowClone(span)
assert.Equal(
t,
option[string]{V: "foo", OK: true},
spanClone.Props().key(),
)
}
func TestDontPanicOnShortPropertyKey(t *testing.T) {
assert.NoError(t, ValidateHProps(HProps{"": "y"}))
assert.NoError(t, ValidateHProps(HProps{"o": "y"}))
}
func TestValidateHPropsReturnsErrorIfOtherHasInvalidType(t *testing.T) {
assert.Error(t, ValidateHProps(HProps{"x": []string{"foo"}}))
}
func TestValidateHPropsDoesNotReturnErrorOnNilEventListener(t *testing.T) {
assert.NoError(t, ValidateHProps(HProps{"onclick": nil}))
}
func TestMergeNilHPropsIntoNilHProps(t *testing.T) {
var props1 HProps = nil
var props2 HProps = nil
props1.Merge(props2)
assert.Equal(t, HProps{}, props1)
}
func TestMergeHPropsIntoNilHProps(t *testing.T) {
var props1 HProps = nil
var props2 HProps = HProps{"foo": "bar"}
props1.Merge(props2)
assert.Equal(t, HProps{"foo": "bar"}, props1)
}
func TestMergeNilHPropsIntoHProps(t *testing.T) {
var props1 HProps = HProps{"foo": "bar"}
var props2 HProps = nil
props1.Merge(props2)
assert.Equal(t, HProps{"foo": "bar"}, props1)
}
func TestMergeHPropsIntoHProps(t *testing.T) {
var props1 HProps = HProps{"foo": "bar"}
var props2 HProps = HProps{"baz": "qux"}
props1.Merge(props2)
assert.Equal(t, HProps{"foo": "bar", "baz": "qux"}, props1)
}
func TestMergeHPropsWithSameKeyIntoHProps(t *testing.T) {
var props1 HProps = HProps{"foo": "bar"}
var props2 HProps = HProps{"foo": "qux"}
props1.Merge(props2)
assert.Equal(t, HProps{"foo": "qux"}, props1)
}
func TestMergeHPropsSlice(t *testing.T) {
props1 := HProps{"foo": "bar"}
props2 := HProps{"baz": "qux"}
props3 := HProps{"quux": "corge", "foo": "qux"}
props := MergeHProps(props1, props2, props3)
assert.Equal(t, HProps{"foo": "qux", "baz": "qux", "quux": "corge"}, props)
}