Skip to content

Commit

Permalink
Merge pull request #24 from ymmooot/no_tag
Browse files Browse the repository at this point in the history
not make jsonld tags when jsonld method returns null
  • Loading branch information
ymmooot authored Jun 7, 2019
2 parents 53d692e + c4c8b0d commit c698195
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/createMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default (options: Options = {}): JsonldMixin => {
return {};
}

if (this.$options.jsonld.call(this) === null) {
return {};
}

const stringifiedJson = JSON.stringify(this.$options.jsonld.call(this), null, mergedOptions.space);
const innerHTML = mergedOptions.space === 0 ? stringifiedJson : `\n${stringifiedJson}\n`;

Expand Down
6 changes: 6 additions & 0 deletions test/createMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ describe('with jsonld', () => {
});
});

test('head method returns an empty object when jsonld returns null', () => {
const mock = mockInstanceFactory();
mock.$options.jsonld = () => null;
expect(mock.$options.head.call(mock)).toEqual({});
})

describe('customizing indentation', () => {
test('using tab', () => {
const mock = mockInstanceFactory({ space: '\t' });
Expand Down

0 comments on commit c698195

Please sign in to comment.