-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate tests that require polyfill from tests that do not
- Loading branch information
1 parent
804bfcd
commit 3a6f625
Showing
3 changed files
with
87 additions
and
99 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/ui/components/core/test/SlotMixin.no-polyfill.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import sinon from 'sinon'; | ||
import { defineCE, expect, html } from '@open-wc/testing'; | ||
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js'; | ||
import { SlotMixin } from '@lion/ui/core.js'; | ||
import { LitElement } from 'lit'; | ||
|
||
it('does not scope elements when polyfill not loaded', async () => { | ||
// @ts-expect-error | ||
ShadowRoot.prototype.createElement = null; | ||
class ScopedEl extends LitElement {} | ||
|
||
const tagName = defineCE( | ||
class extends ScopedElementsMixin(SlotMixin(LitElement)) { | ||
static get scopedElements() { | ||
return { | ||
// @ts-expect-error | ||
...super.scopedElements, | ||
'scoped-el': ScopedEl, | ||
}; | ||
} | ||
|
||
get slots() { | ||
return { | ||
...super.slots, | ||
template: () => html`<scoped-el></scoped-el>`, | ||
}; | ||
} | ||
|
||
render() { | ||
return html`<slot name="template"></slot>`; | ||
} | ||
}, | ||
); | ||
|
||
const renderTarget = document.createElement('div'); | ||
const el = document.createElement(tagName); | ||
|
||
// We don't use fixture, so we limit the amount of calls to document.createElement | ||
const docSpy = sinon.spy(document, 'createElement'); | ||
document.body.appendChild(renderTarget); | ||
renderTarget.appendChild(el); | ||
|
||
expect(docSpy.callCount).to.equal(2); | ||
|
||
document.body.removeChild(renderTarget); | ||
docSpy.restore(); | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/ui/components/core/test/SlotMixin.polyfill.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sinon from 'sinon'; | ||
import { defineCE, expect, fixture, unsafeStatic, html } from '@open-wc/testing'; | ||
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js'; | ||
import { SlotMixin } from '@lion/ui/core.js'; | ||
import { LitElement } from 'lit'; | ||
|
||
it('supports scoped elements when polyfill loaded', async () => { | ||
// @ts-ignore the scoped-custom-element-registry polyfill makes sure `ShadowRoot.prototype.createElement` is defined | ||
const spy = sinon.spy(ShadowRoot.prototype, 'createElement'); | ||
|
||
class ScopedEl extends LitElement {} | ||
|
||
const tagName = defineCE( | ||
class extends ScopedElementsMixin(SlotMixin(LitElement)) { | ||
static get scopedElements() { | ||
return { | ||
// @ts-expect-error | ||
...super.scopedElements, | ||
'scoped-elm': ScopedEl, | ||
}; | ||
} | ||
|
||
get slots() { | ||
return { | ||
...super.slots, | ||
template: () => html`<scoped-elm></scoped-elm>`, | ||
}; | ||
} | ||
|
||
render() { | ||
return html`<slot name="template"></slot>`; | ||
} | ||
}, | ||
); | ||
|
||
const tag = unsafeStatic(tagName); | ||
await fixture(html`<${tag}></${tag}>`); | ||
|
||
expect(spy.getCalls()).to.have.length(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters