I have a stencil component that looks something like this:
export class MyBadge {
@Prop() skin: string = 'primary';
render(){
return (
<span class={`skin-${this.skin}`} />
)
I want to write a unit test that checks that the rendered component applies the given skin
property.
I have a test that compares the rendered component to my expected html, using expect(page.root).toEqualHtml(´< span class=primary >´).
This test works! However, when I try to modify the prop, using template, it fails to run the test.
import { newSpecPage } from '@stencil/core/testing';
import { MyBadge } from './my-badge'
it('should have "secondary" skin', async () => {
const page = newSpecPage({
components: [MyBadge],
template: () => (`
<my-badge skin=secondary></my-badge>
`),
});
expect(page.root).toEqualHtml(`
<span class="skin-secondary">
...
`);
});
This gives the error expect toEqualHtml() value is "null"
and the test fails
I have also tried including the bellow html under the it
, but that fails too.
html: `<my-badge></my-badge>`,
Removing the template option makes the test work, however it then does not see the updated prop.
I wanted to use the template option based on this answer: https://github.com/ionic-team/stencil/issues/1923
I've also tried a few different syntaxes, I'm not clear on how to wrap the template string.
I've been looking around for documentation on this but I can't seem to find what I'm looking for. Any help would be appreciated!
Edit: Cleaned up the code based on suggestions from @Simon Hänisch