Skip to content

Commit

Permalink
Merge pull request #77 from seanpdoyle/add-test-coverage
Browse files Browse the repository at this point in the history
Add test coverage for both built-in processor strategies
  • Loading branch information
keithamus authored Dec 15, 2024
2 parents 4e11d16 + 4e442b7 commit 65aa8f5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/template-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,32 @@ describe('template-instance', () => {
root.appendChild(instance)
expect(root.innerHTML).to.equal(`<div>Hello world</div>`)
})
it('applies data to nested templated element nodes', () => {
it('applies data to nested templated element nodes with the default processPropertyIdentity', () => {
const root = document.createElement('div')
const template = Object.assign(document.createElement('template'), {
innerHTML: '<template><div>{{x}}</div></template>',
})
root.appendChild(new TemplateInstance(template, {x: 'Hello world'}))
const instance = new TemplateInstance(template, {x: 'Hello world'})

root.appendChild(instance)
expect(root.innerHTML).to.equal('<template><div>Hello world</div></template>')
expect(template.innerHTML).to.equal('<template><div>{{x}}</div></template>')
instance.update({x: 'Goodbye world'})
expect(root.innerHTML).to.equal('<template><div>Goodbye world</div></template>')
expect(template.innerHTML).to.equal('<template><div>{{x}}</div></template>')
})
it('applies data to nested templated element nodes with propertyIdentityOrBooleanAttribute', () => {
const template = Object.assign(document.createElement('template'), {
innerHTML: '<template><div hidden="{{hidden}}"></div></template>',
})
const instance = new TemplateInstance(template, {hidden: true}, propertyIdentityOrBooleanAttribute)

const root = document.createElement('div')
root.appendChild(instance)
expect(root.innerHTML).to.equal('<template><div hidden=""></div></template>')
expect(template.innerHTML).to.equal('<template><div hidden="{{hidden}}"></div></template>')
instance.update({hidden: false})
expect(root.innerHTML).to.equal('<template><div></div></template>')
})
it('applies data to templated DocumentFragment nodes', () => {
const template = document.createElement('template')
Expand Down Expand Up @@ -361,7 +379,7 @@ describe('template-instance', () => {
})

describe('handling InnerTemplatePart', () => {
it('makes outer state available to inner parts', () => {
it('makes outer state available to InnerTemplatePart elements with [directive]', () => {
const processor = createProcessor((part, value, state) => {
if (part instanceof InnerTemplatePart && part.directive === 'if') {
if (typeof state === 'object' && (state as Record<string, unknown>)[part.expression]) {
Expand Down

0 comments on commit 65aa8f5

Please sign in to comment.