Skip to content
Open
Show file tree
Hide file tree
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 testing of caching
  • Loading branch information
jeswr committed Oct 27, 2023
commit f72a98ae0e8b99bff781e8b369edb75579ace4ad
2 changes: 1 addition & 1 deletion lib/ContextParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ must be one of ${Util.CONTAINERS.join(', ')}`, ERROR_CODES.INVALID_CONTAINER_MAP
* @return {Promise<JsonLdContextNormalized>} A promise resolving to the context.
*/
private async _parse(context: JsonLdContext,
options: IParseOptions = {}): Promise<JsonLdContextNormalized> {
options: IParseOptions): Promise<JsonLdContextNormalized> {
const {
baseIRI,
parentContext: parentContextInitial,
Expand Down
18 changes: 14 additions & 4 deletions test/ContextParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,19 +1444,29 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
});

describe('parse', () => {
it('should error when parsing a context with an invalid context entry', () => {
return expect(parser.parse({ '@base': true })).rejects
it('should error when parsing a context with an invalid context entry', async () => {
await expect(parser.parse({ '@base': true })).rejects
.toEqual(new ErrorCoded('Found an invalid @base IRI: true',
ERROR_CODES.INVALID_BASE_IRI));

// Testing multiple times to make sure that rejection works with caching
await expect(parser.parse({ '@base': true })).rejects
.toEqual(new ErrorCoded('Found an invalid @base IRI: true',
ERROR_CODES.INVALID_BASE_IRI));
});

it('should parse an object with direct context values', () => {
return expect(parser.parse({ name: "http://xmlns.com/foaf/0.1/name" })).resolves
it('should parse an object with direct context values', async () => {
await expect(parser.parse({ name: "http://xmlns.com/foaf/0.1/name" })).resolves
.toEqual(new JsonLdContextNormalized({
name: "http://xmlns.com/foaf/0.1/name",
}));
});

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 parse an object with indirect context values', () => {
return expect(parser.parse({ "@context": { name: "http://xmlns.com/foaf/0.1/name" } })).resolves
.toEqual(new JsonLdContextNormalized({
Expand Down