当我为组件运行单元测试时出现错误 1) TestWindow 不是构造函数 2) 无法读取未定义的属性“textContent” 无法理解如何进一步进行。当我尝试控制台元素和 testWindow 时,两者都未定义。
**tsx file**
import { Component } from '@stencil/core';
@Component({
tag: 'my-header',
styleUrl: 'my-header.css'
})
export class MyHeader {
render() {
return (
<div>
<p>Hello MyHeader!</p>
</div>
);
}
}
**Spec file**
import { TestWindow } from '@stencil/core/testing';
import { MyHeader } from './my-header';
describe('my-header', () => {
it('should build', () => {
expect(new MyHeader()).toBeTruthy();
});
describe('rendering', () => {
let element: HTMLMyHeaderElement;
let testWindow: TestWindow;
beforeEach(async () => {
testWindow = new TestWindow();
element = await testWindow.load({
components: [MyHeader],
html: '<my-header></my-header>'
});
});
console.log("element ",element);
console.log("testWindow ",testWindow);
it('should show content', () => {
expect(element.textContent).toEqual('');
});
});
});
package.json "devDependencies": { "@stencil/core": "~0.16.4", "@stencil/sass": "^0.1.1", "@types/jest": "23.3.11", " @types/puppeteer”:“1.6.4”,“jest”:“^23.6.0”,“jest-cli”:“23.6.0”,“puppeteer”:“1.8.0”,“workbox-build” : "3.4.1" } 我怎样才能摆脱这些错误,或者我错过了一些要包括的东西。