Skip to content

Commit

Permalink
test: add more tests for light DOM inheritance (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Aug 23, 2021
1 parent 1bc6c1c commit 680ae52
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import { createElement, setFeatureFlagForTest } from 'lwc';

import Test from 'x/test';
import ShadowExtendsLight from 'x/shadowExtendsLight';
import DefaultExtendsLight from 'x/defaultExtendsLight';
import LightExtendsShadow from 'x/lightExtendsShadow';
import DefaultExtendsShadow from 'x/defaultExtendsShadow';

describe('with base class light and subclass shadow', () => {
describe('light/shadow inheritance from base classes', () => {
beforeEach(() => {
setFeatureFlagForTest('ENABLE_LIGHT_DOM_COMPONENTS', true);
});
afterEach(() => {
setFeatureFlagForTest('ENABLE_LIGHT_DOM_COMPONENTS', false);
});
it('should render properly', () => {
const elm = createElement('x-test', { is: Test });
expect(elm.shadowRoot).not.toBeNull();
});

const testCases = [
{ tag: 'x-shadow-extends-light', is: ShadowExtendsLight, shadow: true },
{ tag: 'x-default-extends-light', is: DefaultExtendsLight, shadow: false },
{ tag: 'x-light-extends-shadow', is: LightExtendsShadow, shadow: false },
{ tag: 'x-default-extends-shadow', is: DefaultExtendsShadow, shadow: true },
];

for (const { tag, is, shadow } of testCases) {
it(`renders ${is.name}`, () => {
const elm = createElement(tag, { is });
document.body.appendChild(elm);
if (shadow) {
expect(elm.shadowRoot).not.toBeNull();
} else {
expect(elm.shadowRoot).toBeNull();
}
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template lwc:render-mode="light"></template>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class Base extends LightningElement {
export default class BaseLight extends LightningElement {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template></template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class BaseShadow extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template lwc:render-mode="light"></template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import BaseLight from 'x/baseLight';

export default class DefaultExtendsLight extends BaseLight {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template></template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import BaseShadow from 'x/baseShadow';

export default class DefaultExtendsShadow extends BaseShadow {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template lwc:render-mode="light">
<x-test data-id="x-test"></x-test>
<p></p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseShadow from 'x/baseShadow';

export default class LightExtendsShadow extends BaseShadow {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p></p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseLight from 'x/baseLight';

export default class ShadowExtendsLight extends BaseLight {
static renderMode = 'shadow';
}

This file was deleted.

This file was deleted.

0 comments on commit 680ae52

Please sign in to comment.