|
| 1 | +import sinon from 'sinon'; |
| 2 | +import { fixtureSync } from '@vaadin/testing-helpers'; |
| 3 | +import { expect } from '@esm-bundle/chai'; |
| 4 | +import { PolymerElement } from '@polymer/polymer/polymer-element.js'; |
| 5 | + |
| 6 | +import { processTemplates } from '../templates.js'; |
| 7 | + |
| 8 | +class ComponentElement extends PolymerElement { |
| 9 | + static get is() { |
| 10 | + return 'component-element'; |
| 11 | + } |
| 12 | + |
| 13 | + ready() { |
| 14 | + super.ready(); |
| 15 | + |
| 16 | + processTemplates(this); |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +customElements.define(ComponentElement.is, ComponentElement); |
| 21 | + |
| 22 | +describe('process templates', () => { |
| 23 | + beforeEach(() => { |
| 24 | + sinon.stub(console, 'warn'); |
| 25 | + }); |
| 26 | + |
| 27 | + afterEach(() => { |
| 28 | + console.warn.restore(); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('with template renderer', () => { |
| 32 | + beforeEach(() => { |
| 33 | + window.Vaadin = window.Vaadin || {}; |
| 34 | + window.Vaadin.templateRendererCallback = sinon.spy(); |
| 35 | + }); |
| 36 | + |
| 37 | + afterEach(() => { |
| 38 | + window.Vaadin.templateRendererCallback = undefined; |
| 39 | + }); |
| 40 | + |
| 41 | + it('should invoke the template renderer callback', () => { |
| 42 | + const component = fixtureSync(` |
| 43 | + <component-element> |
| 44 | + <template></template> |
| 45 | + </component-element> |
| 46 | + `); |
| 47 | + |
| 48 | + expect(window.Vaadin.templateRendererCallback.calledOnce).to.be.true; |
| 49 | + expect(window.Vaadin.templateRendererCallback.args[0][0]).to.equal(component); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should not show the deprecation warning', () => { |
| 53 | + expect(console.warn.called).to.be.false; |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('without template renderer', () => { |
| 58 | + it('should show the deprecation warning', () => { |
| 59 | + fixtureSync(` |
| 60 | + <component-element> |
| 61 | + <template></template> |
| 62 | + </component-element> |
| 63 | + `); |
| 64 | + |
| 65 | + expect(console.warn.calledOnce).to.be.true; |
| 66 | + expect(console.warn.args[0][0]).to.equal( |
| 67 | + `WARNING: <template> inside <component-element> is no longer supported. Import @vaadin/vaadin-template-renderer to enable compatibility (see https://vaad.in/template-renderer)` |
| 68 | + ); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments