This file contains hidden or 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
import { TestWindow } from '@stencil/core/testing'; | |
import { Adder } from './adder'; | |
describe('adder', () => { | |
it('should build', () => { | |
expect(new Adder()).toBeTruthy(); | |
}); | |
describe('rendering', () => { |
This file contains hidden or 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
import { Component } from '@stencil/core'; | |
@Component({ | |
tag: 'adder', | |
}) | |
export class Adder { | |
render() { | |
return (<div></div>); | |
} | |
} |
This file contains hidden or 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
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; | |
} |
This file contains hidden or 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
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', () => { |
This file contains hidden or 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
render(): JSX.Element { | |
return '4'; | |
} |
This file contains hidden or 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
export class Adder { | |
@Prop() a: number; | |
@Prop() b: number; | |
render(): JSX.Element { | |
return this.a + this.b; | |
} | |
} |
This file contains hidden or 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
interface Adder { | |
'a': number; | |
'b': number; | |
} |
This file contains hidden or 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
it('updates the result if we change the props', () => { | |
element.a = 1; | |
element.b = 1; | |
expect(element.textContent).toEqual('1'); | |
}); |
This file contains hidden or 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
it('updates the result if we change the props', async () => { | |
element.a = 1; | |
element.b = 1; | |
await testWindow.flush(); | |
expect(element.textContent).toEqual('2'); | |
}); |
This file contains hidden or 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
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); |