Skip to content

Commit

Permalink
Add safe canonize mode tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlehn authored and dlongley committed Aug 23, 2022
1 parent 0229176 commit 16a040b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/misc.js
Expand Up @@ -3417,3 +3417,53 @@ _:b0 <ex:p> "v" .
});
});
});

describe('safe canonize defaults', () => {
it('does not throw on safe input', async () => {
const input =
{
"@id": "ex:id",
"ex:p": "v"
}
;
const expected =
'<ex:id> <ex:p> "v" .\n'
;
const result = await jsonld.canonize(input);
assert.deepStrictEqual(result, expected);
});

it('throws on unsafe input', async () => {
const input =
{
"@id": "ex:id",
"ex:p": "v",
"unknown": "error"
}
;
let error;
try {
await jsonld.canonize(input);
} catch(e) {
error = e;
}
assert(error, 'missing safe validation error');
});

it('allows override of safe mode', async () => {
const input =
{
"@id": "ex:id",
"ex:p": "v",
"unknown": "error"
}
;
const expected =
'<ex:id> <ex:p> "v" .\n'
;
const result = await jsonld.canonize(input, {
safe: false
});
assert.deepStrictEqual(result, expected);
});
});

0 comments on commit 16a040b

Please sign in to comment.