Skip to content

Commit

Permalink
test: migrate test suites with skipped unit tests to karma (#1753)
Browse files Browse the repository at this point in the history
* test: remove unit tests related to global attribute restriction
restriction was removed via #1362
* test: update error message in scoped-ids.spec.ts
* test: update test to match <slot> element spec
* test: remove unit test that was testing non-existent functions
* test: migrate tests to integration-karma
* test: migrate scoped-ids.spec to karma suite
* test: migrate html-element.spec.ts to karma
* test: migrate traverse.spec.ts to karma suite
  • Loading branch information
ravijayaramappa authored Mar 11, 2020
1 parent 62d28c7 commit c1b56ec
Show file tree
Hide file tree
Showing 91 changed files with 1,065 additions and 2,775 deletions.
606 changes: 0 additions & 606 deletions packages/@lwc/engine/src/__tests__/focus.spec.ts

This file was deleted.

565 changes: 0 additions & 565 deletions packages/@lwc/engine/src/__tests__/traverse.spec.ts

This file was deleted.

1,485 changes: 0 additions & 1,485 deletions packages/@lwc/engine/src/framework/__tests__/html-element.spec.ts

This file was deleted.

111 changes: 0 additions & 111 deletions packages/@lwc/engine/src/framework/__tests__/scoped-ids.spec.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/integration-karma/helpers/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,19 @@ window.TestUtils = (function(lwc, jasmine, beforeAll) {
register = {};
}

// #986 - childNodes on the host element returns a fake shadow comment node on IE11 for debugging purposed. This method
// filters this node.
function getHostChildNodes(host) {
return Array.prototype.slice.call(host.childNodes).filter(function(n) {
return !(n.nodeType === Node.COMMENT_NODE && n.tagName.startsWith('#shadow-root'));
});
}
return {
registerForLoad: registerForLoad,
clearRegister: clearRegister,
load: load,
extractDataIds: extractDataIds,
extractShadowDataIds: extractShadowDataIds,
getHostChildNodes: getHostChildNodes,
};
})(LWC, jasmine, beforeAll);
11 changes: 11 additions & 0 deletions packages/integration-karma/test/component/aom-setter/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createElement } from 'lwc';

import Parent from 'x/parent';

import RoleTester, { roleSetterCallCount } from 'x/roleTester';

let parent;

beforeAll(() => {
Expand All @@ -24,3 +26,12 @@ it('should reflect AOM attribute for native element', () => {
const elm = parent.shadowRoot.querySelector('div');
expect(elm.getAttribute('aria-label')).toBe('KIX to HKG');
});

describe('#role', () => {
it('should call setter when defined', () => {
const element = createElement('prop-getter-aria-role', { is: RoleTester });
document.body.appendChild(element);
element.role = 'tab';
expect(roleSetterCallCount).toBe(1);
});
});
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,12 @@
import { LightningElement, api } from 'lwc';

export let roleSetterCallCount = 0;
export default class MyComponent extends LightningElement {
get role() {
return 'role';
}
@api
set role(value) {
roleSetterCallCount += 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ConstructorGetterAccess from 'x/constructorGetterAccess';
import Reactivity from 'x/reactivity';
import Methods from 'x/methods';
import Inheritance from 'x/inheritance';
import NullInitialValue from 'x/nullInitialValue';

describe('properties', () => {
it('should expose class properties with the api decorator', () => {
Expand Down Expand Up @@ -104,3 +105,9 @@ describe('inheritance', () => {
expect(elm.overriddenMethod()).toBe('overridden - child');
});
});

it('should not log an error when initializing api value to null', () => {
const elm = createElement('x-foo-init-api', { is: NullInitialValue });

expect(() => document.body.appendChild(elm)).not.toLogErrorDev();
});
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,5 @@
import { LightningElement, api } from 'lwc';
export default class MyComponent extends LightningElement {
@api
foo = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createElement } from 'lwc';

import Properties from 'x/properties';
import SideEffect from 'x/sideEffect';
import NonObservable from 'x/nonObservable';
import SetTrackedValueToNull from 'x/setTrackedValueToNull';

it('rerenders the component when a track property is updated - literal', () => {
const elm = createElement('x-properties', { is: Properties });
Expand Down Expand Up @@ -91,6 +93,12 @@ describe('object mutations', () => {
expect(elm.shadowRoot.querySelector('.obj').textContent).toBe('1');
});
});

it('should not log an error when setting tracked value to null', () => {
const elm = createElement('x-foo-tracked-null', { is: SetTrackedValueToNull });

expect(() => document.body.appendChild(elm)).not.toLogErrorDev();
});
});

describe('array mutations', () => {
Expand Down Expand Up @@ -124,3 +132,13 @@ describe('array mutations', () => {
});
});
});

describe('non-observable values', () => {
it('should not throw an error when accessing a non-observable property from a tracked property before rendering', () => {
const elm = createElement('x-foo', { is: NonObservable });
elm.foo = new Map();
expect(() => {
elm.foo;
}).not.toThrow();
});
});
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,14 @@
import { LightningElement, track, api } from 'lwc';

export default class MyComponent extends LightningElement {
@track
state = {};

@api
set foo(value) {
this.state.foo = value;
}
get foo() {
return this.state.foo;
}
}
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,10 @@
import { LightningElement, track } from 'lwc';

export default class MyComponent extends LightningElement {
@track
state = {};
connectedCallback() {
this.state.foo = null;
this.state.foo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createElement } from 'lwc';

import LockerIntegration from 'x/lockerIntegration';

it('should support Locker integration which uses a wrapped LightningElement base class', () => {
const elm = createElement('x-secure-parent', { is: LockerIntegration });
document.body.appendChild(elm);
// Verifying that shadow tree was created to ensure the component class was successfully processed
const actual = elm.querySelector('div.secure');
expect(actual).toBeDefined();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div class="secure"></div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LightningElement } from 'lwc';
import Template from './lockerIntegration.html';
function SecureBase() {
if (this instanceof SecureBase) {
LightningElement.prototype.constructor.call(this);
} else {
return LightningElement;
}
}
SecureBase.__circular__ = true;
export default class Foo extends SecureBase {
render() {
return Template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { createElement } from 'lwc';
import { getHostChildNodes } from 'test-utils';

import SimpleParent from 'x/simpleParent';
import SlottedParent from 'x/slotted';
import SlottedCustomElement from 'x/slottedCustomElement';
import SlotReceiver from 'x/slot';
import CustomElementAsDefaultSlot from 'x/customElementAsDefaultSlot';
import TextSlotted from 'x/textSlotted';

describe('assignedSlot', () => {
it('should return null when custom element is not in slot', () => {
const elm = createElement('x-assigned-slot', { is: SimpleParent });
document.body.appendChild(elm);
const child = elm.shadowRoot.querySelector('x-no-slot');
expect(child.assignedSlot).toBe(null);
});

it('should return null when native element is not in slot', () => {
const elm = createElement('x-assigned-slot', { is: SimpleParent });
document.body.appendChild(elm);
const child = elm.shadowRoot.querySelector('div');
expect(child.assignedSlot).toBe(null);
});

it('should return the correct slot when native element is slotted', () => {
const elm = createElement('x-native-slotted-component', { is: SlottedParent });
document.body.appendChild(elm);
const slot = elm.shadowRoot.querySelector('x-slot').shadowRoot.querySelector('slot');
const child = elm.shadowRoot.querySelector('div');
expect(child.assignedSlot).toBe(slot);
});

it('should return the correct slot when custom element is slotted', () => {
const elm = createElement('x-custom-slotted-component', { is: SlottedCustomElement });
document.body.appendChild(elm);
const slot = elm.shadowRoot.querySelector('x-slot').shadowRoot.querySelector('slot');
const child = elm.shadowRoot.querySelector('x-child');
expect(child.assignedSlot).toBe(slot);
});

it('should return the correct named slot when native element is slotted', () => {
const elm = createElement('x-native-slotted-component', { is: SlottedParent });
document.body.appendChild(elm);
const slot = elm.shadowRoot.querySelector('x-named-slot').shadowRoot.querySelector('slot');
const child = elm.shadowRoot.querySelector('div.named');
expect(child.assignedSlot).toBe(slot);
});

it('should return the correct named slot when custom element is slotted', () => {
const elm = createElement('x-custom-slotted-component', { is: SlottedCustomElement });
document.body.appendChild(elm);
const slot = elm.shadowRoot.querySelector('x-named-slot').shadowRoot.querySelector('slot');
const child = elm.shadowRoot.querySelector('x-child.named');
expect(child.assignedSlot).toBe(slot);
});

it('should return null when native element default slot content', () => {
const elm = createElement('x-assigned-slot', { is: SlotReceiver });
document.body.appendChild(elm);
const child = elm.shadowRoot.querySelector('div');
expect(child.assignedSlot).toBe(null);
});

it('should return null when custom element default slot content', () => {
const elm = createElement('x-assigned-slot', { is: CustomElementAsDefaultSlot });
document.body.appendChild(elm);
const child = elm.shadowRoot.querySelector('x-child');
expect(child.assignedSlot).toBe(null);
});

it('should return the correct slot when text is slotted', () => {
const elm = createElement('x-native-slotted-component', { is: TextSlotted });
document.body.appendChild(elm);
const slot = elm.shadowRoot.querySelector('x-slot').shadowRoot.querySelector('slot');
const text = getHostChildNodes(elm.shadowRoot.querySelector('x-slot'))[0];
expect(text.assignedSlot).toBe(slot);
});
});
Loading

0 comments on commit c1b56ec

Please sign in to comment.