TestWindow不是Stenciljs单元测试中的构造函数

时间:2019-01-24 10:47:23

标签: stenciljs

运行组件的单元测试时出错 1)TestWindow不是构造函数 2)无法读取未定义的属性“ textContent” 无法理解如何继续进行。当我尝试控制台element和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”           }         我该如何消除这些错误,或者我缺少要包含的内容。

1 个答案:

答案 0 :(得分:0)

整个Stencil单元测试已更改为最新版本。 现在不推荐使用TestWindow,而推荐使用Jest和Puppeteer的组合。 您应该查阅文档以获取有关如何测试代码的进一步说明:end to end testing in Stencil