-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwas_error.test.js
More file actions
67 lines (62 loc) · 1.67 KB
/
Copy pathwas_error.test.js
File metadata and controls
67 lines (62 loc) · 1.67 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
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
const {
default: component,
} = await import('./was_error.js')
describe(component.name, () => {
it('should return true if any given error is true', async () => {
component.errors = [
false,
true,
false,
]
const returnValue = await component.run()
assert.equal(returnValue, true)
})
it('should return false when no given error is true', async () => {
component.errors = [
false,
false,
false,
]
const returnValue = await component.run()
assert.equal(returnValue, false)
})
it('should handle non-boolean truthy values correctly', async () => {
const truthyNonBooleanValues = [
'asdf',
['a'],
[],
2,
]
for (const truthyNonBooleanValue of truthyNonBooleanValues) {
component.errors = [truthyNonBooleanValue]
const returnValue = await component.run()
assert.equal(
returnValue,
true,
`Failed to treat ${JSON.stringify(truthyNonBooleanValue)} as true.`
)
}
})
it('should handle non-boolean falsy values correctly', async () => {
// For details about "falsy" see the docs:
// https://developer.mozilla.org/en-US/docs/Glossary/Falsy
const falsyNonBooleanValues = [
null,
undefined,
NaN,
0,
'',
]
for (const falsyNonBooleanValue of falsyNonBooleanValues) {
component.errors = [falsyNonBooleanValue]
const returnValue = await component.run()
assert.equal(
returnValue,
false,
`Failed to treat ${JSON.stringify(falsyNonBooleanValue)} as false.`
)
}
})
})