Skip to content

Commit 0481eec

Browse files
committed
test(URL): write tests for the URL interface and URLSearchParams
1 parent 542894e commit 0481eec

File tree

3 files changed

+1644
-0
lines changed

3 files changed

+1644
-0
lines changed

tests/js/quint.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file quint.js
3+
* A minimum testing framework with QUnit-like (https://qunitjs.com/) APIs
4+
* @author Tom Tang <[email protected]>
5+
* @date Aug 2023
6+
*/
7+
8+
const QUnitAssert = {
9+
arity(fn, length)
10+
{
11+
if (fn.length !== length) throw new Error(`'${fn}' does not have arity of ${length}`);
12+
},
13+
isFunction(x)
14+
{
15+
if (typeof x !== 'function') throw new Error(`'${x}' is not a function`);
16+
},
17+
name(x, name)
18+
{
19+
if (x.name !== name) throw new Error(`'${x}' does not have a name of ${name}`);
20+
},
21+
true(x)
22+
{
23+
if (x !== true) throw new Error(`'${x}' is not true`);
24+
},
25+
false(x)
26+
{
27+
if (x !== false) throw new Error(`'${x}' is not false`);
28+
},
29+
same(a, b)
30+
{
31+
if (a !== b) throw new Error(`'${a}' does not equal to '${b}'`);
32+
},
33+
arrayEqual(a, b)
34+
{
35+
if (JSON.stringify(a) !== JSON.stringify(b)) throw new Error(`'${a}' does not equal to '${b}'`);
36+
},
37+
throws(fn, error)
38+
{
39+
try
40+
{
41+
fn();
42+
}
43+
catch (err)
44+
{
45+
if (!err.toString().includes(error)) throw new Error(`'${fn}' throws '${err}' but expects '${error}'`);
46+
return;
47+
}
48+
throw new Error(`'${fn}' does not throw`);
49+
},
50+
looksNative(fn)
51+
{
52+
if (!fn.toString().includes('[native code]')) throw new Error(`'${fn}' does not look native`);
53+
},
54+
enumerable(obj, propertyName)
55+
{
56+
const descriptor = Object.getOwnPropertyDescriptor(obj, propertyName);
57+
if (!descriptor.enumerable) throw new Error(`'${obj[Symbol.toStringTag]}.${propertyName}' is not enumerable`);
58+
},
59+
};
60+
61+
const QUnit = {
62+
test(name, callback)
63+
{
64+
callback(QUnitAssert);
65+
},
66+
skip(name, callback)
67+
{
68+
// no op
69+
}
70+
};
71+
72+
module.exports = QUnit;

0 commit comments

Comments
 (0)