Skip to content

Instantly share code, notes, and snippets.

View MonsieurMan's full-sized avatar

Ange Picard MonsieurMan

View GitHub Profile
describe('adder', () => {
it('should build', () => {
expect(new Adder()).toBeTruthy();
});
it('adds up the two values', () => {
const adder = new Adder();
adder.a = 1;
adder.b = 1;
expect(adder.value).toEqual(2);
it('updates the result if we change the props', async () => {
element.a = 1;
element.b = 1;
await testWindow.flush();
expect(element.textContent).toEqual('2');
});
it('updates the result if we change the props', () => {
element.a = 1;
element.b = 1;
expect(element.textContent).toEqual('1');
});
interface Adder {
'a': number;
'b': number;
}
export class Adder {
@Prop() a: number;
@Prop() b: number;
render(): JSX.Element {
return this.a + this.b;
}
}
render(): JSX.Element {
return '4';
}
beforeEach(async () => {
testWindow = new TestWindow();
element = await testWindow.load({
components: [Adder],
// Let's say we want to props `a` and `b`
html: '<adder a="2" b="2"></adder>',
});
});
it('adds up the two values and display it in the text content', () => {
declare global {
// This is actually merging to the HTMLElement DOM Interface
interface HTMLElement {
componentOnReady?: () => Promise<this | null>;
}
interface HTMLStencilElement extends HTMLElement {
componentOnReady(): Promise<this>;
forceUpdate(): void;
}
import { Component } from '@stencil/core';
@Component({
tag: 'adder',
})
export class Adder {
render() {
return (<div></div>);
}
}
@MonsieurMan
MonsieurMan / adder.spec.ts
Last active August 10, 2018 07:26
Unit testing Stencil component
import { TestWindow } from '@stencil/core/testing';
import { Adder } from './adder';
describe('adder', () => {
it('should build', () => {
expect(new Adder()).toBeTruthy();
});
describe('rendering', () => {