Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: improve test coverage
  • Loading branch information
jeswr committed Oct 27, 2023
commit d8c354ff9ac31d5506918224f2fedcfc04b18fae
21 changes: 20 additions & 1 deletion test/ContextParser-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ContextCache,
ContextParser,
ERROR_CODES,
ErrorCoded,
Expand Down Expand Up @@ -1465,7 +1466,25 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
it('should resolve to the same object when parse is called on the same context', async () => {
await expect(parser.parse({ name: "http://xmlns.com/foaf/0.1/name" })).resolves
.toBe(await parser.parse({ name: "http://xmlns.com/foaf/0.1/name" }));
})
});

it('should resolve to the same object when parse is called on the same context and with empty parent', async () => {
await expect(parser.parse({ name: "http://xmlns.com/foaf/0.1/name" })).resolves
.toEqual(await parser.parse({ name: "http://xmlns.com/foaf/0.1/name" }, {
parent: new JsonLdContextNormalized({}),
}));
});

it('should respect the LRU cache and discard elements once max is reached', async () => {
const myParser = new ContextParser({
contextCache: new ContextCache({ max: 1 }),
});

const r1 = await myParser.parse({ name: "http://xmlns.com/foaf/0.1/name" });
await myParser.parse({ name1: "http://xmlns.com/foaf/0.1/name" });
const r3 = await myParser.parse({ name: "http://xmlns.com/foaf/0.1/name" });
expect(r1).not.toBe(r3);
});

it('should parse an object with indirect context values', () => {
return expect(parser.parse({ "@context": { name: "http://xmlns.com/foaf/0.1/name" } })).resolves
Expand Down