Skip to content

Commit

Permalink
Add more insertion non-Object tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623 committed Sep 27, 2023
1 parent 6d418c3 commit 5fcd652
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions spec/spec.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import TemplateTemplate from '../src/templatetemplate.mjs';

describe('TemplateTemplate', () => {
const typeErrorMessage = /is not an HTMLTemplateElement$/;

const buildTemplateElement = (id = 'templ', innerHTML = '<div><a></a></div>') => {
const template = document.createElement('template');

Expand All @@ -18,19 +16,19 @@ describe('TemplateTemplate', () => {

describe('when `template` argument is null', () => {
it('throws a TypeError', () => {
expect(() => TemplateTemplate()).toThrowError(TypeError, typeErrorMessage);
expect(() => TemplateTemplate()).toThrowError(TypeError, /is not an HTMLTemplateElement$/);
});
});

describe('when `template` argument is not an HTMLTemplateElement', () => {
it('throws a TypeError', () => {
expect(() => TemplateTemplate(document.createElement('div'))).toThrowError(TypeError, typeErrorMessage);
expect(() => TemplateTemplate(document.createElement('div'))).toThrowError(TypeError, /is not an HTMLTemplateElement$/);
});
});

describe('when `template` argument references an element that does not exist', () => {
it('throws a TypeError', () => {
expect(() => TemplateTemplate('#foo')).toThrowError(TypeError, typeErrorMessage);
expect(() => TemplateTemplate('#foo')).toThrowError(TypeError, /is not an HTMLTemplateElement$/);
});
});

Expand Down Expand Up @@ -69,7 +67,15 @@ describe('TemplateTemplate', () => {

describe('when `insertions` argument is not an object', () => {
it('throws a TypeError', () => {
expect(() => TemplateTemplate(document.createElement('template'), 'foo')).toThrowError(TypeError, /is not an Object/);
expect(() => TemplateTemplate(document.createElement('template'), 'foo')).toThrowError(TypeError, /is not an Object$/);
});

it('throws a TypeError', () => {
expect(() => TemplateTemplate(document.createElement('template'), null)).toThrowError(TypeError, /is not an Object$/)
});

it('throws a TypeError', () => {
expect(() => TemplateTemplate(document.createElement('template'), [])).toThrowError(TypeError, /is not an Object$/)
});
});

Expand Down

0 comments on commit 5fcd652

Please sign in to comment.