summaryrefslogtreecommitdiffstats
path: root/tests/unit/params.js
blob: 6ac4cc10cdfe63597eb90383328d82104770aa71 (plain)
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
const JsUnit = imports.jsUnit;
const Params = imports.misc.params;

function assertParamsEqual(params, expected) {
    for (let p in params) {
        JsUnit.assertTrue(p in expected);
        JsUnit.assertEquals(params[p], expected[p]);
    }
}

let defaults = {
    foo: 'This is a test',
    bar: null,
    baz: 42
};

assertParamsEqual(
    Params.parse(null, defaults),
    defaults);

assertParamsEqual(
    Params.parse({ bar: 23 }, defaults),
    { foo: 'This is a test', bar: 23, baz: 42 });

JsUnit.assertRaises(
    () => {
        Params.parse({ extraArg: 'quz' }, defaults);
    });

assertParamsEqual(
    Params.parse({ extraArg: 'quz' }, defaults, true),
    { foo: 'This is a test', bar: null, baz: 42, extraArg: 'quz' });