-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
72 lines (63 loc) · 1.85 KB
/
test.js
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
function run(config) {
const wrapper = document.createElement('div')
config.setup(wrapper)
const p = document.createElement('p')
const description = document.createElement('strong')
description.innerHTML = config.description
p.appendChild(description)
try {
const x = xilik(config.props, wrapper)
if (config.test(x, wrapper)) {
p.classList.add('green')
}
else {
console.error('FAILED', config.description)
p.classList.add('red')
}
}
catch (error) {
console.error('FAILED', error)
p.innerHTML += '\n' + error
p.classList.add('red')
}
wrapper.remove()
const $testResultsWrapper = document.getElementById('test-results-wrapper')
$testResultsWrapper.appendChild(p)
}
function update(element, value) {
element.value = value
element.dispatchEvent(new Event('input'))
}
run({
description: '$input.value should change after changing x.props.theInput',
props: {
theInput: 123,
},
setup: wrapper => {
const $input = document.createElement('input')
$input.id = 'theInput'
$input.type = 'number'
wrapper.appendChild($input)
},
test: (xilik, wrapper) => {
xilik.props.theInput = 456
return xilik.props.theInput == wrapper.children.theInput.value
}
})
run({
description: 'x.props.input2 should change after changing $input2.value',
props: {
theInput: 123,
},
setup: wrapper => {
const $input = document.createElement('input')
$input.id = 'theInput'
$input.type = 'number'
wrapper.appendChild($input)
},
test: (xilik, wrapper) => {
const $input = wrapper.children.theInput
update($input, 777)
return xilik.props.theInput.toString() == $input.value
}
})