Skip to content

Instantly share code, notes, and snippets.

@Tallyb
Last active June 5, 2019 15:31
Show Gist options
  • Save Tallyb/da5ced8675c8b098b8159af2c1ac41a2 to your computer and use it in GitHub Desktop.
Save Tallyb/da5ced8675c8b098b8159af2c1ac41a2 to your computer and use it in GitHub Desktop.
Component Logic - Stencil
//instance.tsx
import { Component, Prop } from '@stencil/core';
@Component({
tag: 'my-instance'
})
export class MyInstance {
/**
* The first name
*/
@Prop() first: string;
/**
* The middle name
*/
@Prop() middle: string;
/**
* The last name
*/
@Prop() last: string;
format () {
return [this.first, this.middle, this.last].filter (e => !!e).join(' ');
}
}
// instance.spec.ts
import { MyInstance } from './instance';
it ('Should format the name', () => {
let cmp = new MyInstance();
cmp.first = 'Donald';
cmp.last = 'Duck';
expect(cmp.format()).toEqual('Donald Duck');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment