@@ -37,7 +37,7 @@ export function pass(message = "") {
37
37
}
38
38
39
39
export function fail ( message = "" ) {
40
- return new Response ( message , { status : 500 } ) ;
40
+ throw new Response ( message , { status : 500 } ) ;
41
41
}
42
42
43
43
function prettyPrintSymbol ( a ) {
@@ -48,17 +48,27 @@ function prettyPrintSymbol(a) {
48
48
}
49
49
export function assert ( actual , expected , code ) {
50
50
if ( ! deepEqual ( actual , expected ) ) {
51
- return fail (
51
+ fail (
52
52
`Expected \`${ code } \` to equal \`${ JSON . stringify ( prettyPrintSymbol ( expected ) ) } \` - Found \`${ JSON . stringify ( prettyPrintSymbol ( actual ) ) } \`` ,
53
53
) ;
54
54
}
55
55
}
56
56
57
+ export { assert as strictEqual }
58
+
59
+ export function ok ( truthy , code ) {
60
+ if ( ! truthy ) {
61
+ fail (
62
+ `Expected ${ code ? ' ' + code : '' } to be truthy - Found \`${ JSON . stringify ( prettyPrintSymbol ( truthy ) ) } \`` ,
63
+ ) ;
64
+ }
65
+ }
66
+
57
67
export async function assertResolves ( func ) {
58
68
try {
59
69
await func ( ) ;
60
70
} catch ( error ) {
61
- return fail (
71
+ fail (
62
72
`Expected \`${ func . toString ( ) } \` to resolve - Found it rejected: ${ error . name } : ${ error . message } ` ,
63
73
) ;
64
74
}
@@ -67,63 +77,65 @@ export async function assertResolves(func) {
67
77
export async function assertRejects ( func , errorClass , errorMessage ) {
68
78
try {
69
79
await func ( ) ;
70
- return fail (
71
- `Expected \`${ func . toString ( ) } \` to reject - Found it did not reject` ,
72
- ) ;
73
80
} catch ( error ) {
74
81
if ( errorClass ) {
75
82
if ( error instanceof errorClass === false ) {
76
- return fail (
83
+ fail (
77
84
`Expected \`${ func . toString ( ) } \` to reject instance of \`${ errorClass . name } \` - Found instance of \`${ error . name } \`` ,
78
85
) ;
79
86
}
80
87
}
81
88
82
89
if ( errorMessage ) {
83
90
if ( error . message !== errorMessage ) {
84
- return fail (
91
+ fail (
85
92
`Expected \`${ func . toString ( ) } \` to reject error message of \`${ errorMessage } \` - Found \`${ error . message } \`` ,
86
93
) ;
87
94
}
88
95
}
96
+
97
+ return ;
89
98
}
99
+ fail ( `Expected \`${ func . toString ( ) } \` to reject - Found it did not reject` ) ;
90
100
}
91
101
92
102
export function assertThrows ( func , errorClass , errorMessage ) {
93
103
try {
94
104
func ( ) ;
95
- return fail (
96
- `Expected \`${ func . toString ( ) } \` to throw - Found it did not throw` ,
97
- ) ;
98
105
} catch ( error ) {
99
106
if ( errorClass ) {
100
107
if ( error instanceof errorClass === false ) {
101
- return fail (
108
+ fail (
102
109
`Expected \`${ func . toString ( ) } \` to throw instance of \`${ errorClass . name } \` - Found instance of \`${ error . name } \`: ${ error . message } \n${ error . stack } ` ,
103
110
) ;
104
111
}
105
112
}
106
113
107
114
if ( errorMessage ) {
108
115
if ( error . message !== errorMessage ) {
109
- return fail (
116
+ fail (
110
117
`Expected \`${ func . toString ( ) } \` to throw error message of \`${ errorMessage } \` - Found \`${ error . message } \`` ,
111
118
) ;
112
119
}
113
120
}
121
+
122
+ return ;
114
123
}
124
+ fail ( `Expected \`${ func . toString ( ) } \` to throw - Found it did not throw` ) ;
115
125
}
116
126
117
127
export function assertDoesNotThrow ( func ) {
118
128
try {
119
129
func ( ) ;
120
130
} catch ( error ) {
121
- return fail (
131
+ fail (
122
132
`Expected \`${ func . toString ( ) } \` to not throw - Found it did throw: ${ error . name } : ${ error . message } ` ,
123
133
) ;
124
134
}
125
135
}
126
136
137
+ export { deepEqual as deepStrictEqual }
138
+
127
139
export function deepEqual ( a , b ) {
128
140
var aKeys ;
129
141
var bKeys ;
0 commit comments