Skip to content

Commit

Permalink
fix: tests coverage restored to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Oct 28, 2021
1 parent 46b95ef commit 9abb112
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/fonts/src/mountFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ function getFontCss(font: MountFontParams) {
* ```
*/
export function mountFont(font: MountFontParams) {
const css = getFontCss(font);

const newFontStyle = `
<style class="morfeo-font" id="font-${font.name}">
${css}
</style>
`;

if (globalThis && globalThis.document) {
const css = getFontCss(font);

const newFontStyle = `
<style class="morfeo-font" id="font-${font.name}">
${css}
</style>
`;
unmountFont(font.name);
document.head.innerHTML += newFontStyle;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/fonts/tests/mountFont.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ describe('mountFont', () => {
expect(boldStyle?.textContent).toContain('@import');
});
});

describe('when document is not defined', () => {
test('should not fail', () => {
Object.defineProperty(global, 'globalThis', { get: () => {} });
mountFont({ name: 'should-not-be-added' } as any);
const element = document.getElementById('font-should-not-be-added');
expect(element).toBeNull();
});
});
});

0 comments on commit 9abb112

Please sign in to comment.