1

我正在尝试web-component-tester在 Chrome v69、web-component-test v 6.5.0 和 webcomponentsjs v 2.1.3 中的 Polymer 2 项目上以交互方式运行两个测试。第一次super basic test通过,第二次失败并出现以下错误:

错误:聚合物未在 shop-home.test.html:36 处刷新

<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>shop-home</title>
  <script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <script>void(0)</script>
  <script src="/bower_components/web-component-tester/browser.js"></script>
  <link rel="import" href="/bower_components/test-fixture/test-fixture.html">
 <link rel="import" href="../shop-home.html">

</head>
<body>

  <test-fixture id="basic">
    <template>
       <shop-home></shop-home>
    </template>
  </test-fixture>

  <script>
    suite('shop-home tests', () => {
      var home;

      setup(() => {
        home = fixture('basic');
      });

      test('super basic test', (done) => {
        flush(() => {
          console.log('what a great test')
          done();
        });
      });

      test('load mission statement', (done) => {
        flush(() => {
          let ms = Polymer.dom(home.root).querySelector('mission-statement');
          assert.exists(ms, 'mission statement is neither `null` nor `undefined`');
      done();
    });
  });

});

通过命令行运行时,错误会提供更多详细信息:

错误:在测试函数之外引发错误:document.getElementById(fixtureId).create 不是函数。(在 'document.getElementById(fixtureId).create(model)' 中,'document.getElementById(fixtureId).create' 未定义)在 shop-home.html:25,1 次测试失败,在测试函数之外抛出错误:文档.getElementById(...).create 不是 shop-home.html:25 中的函数

如何防止这种情况并运行适当的单元测试?

4

0 回答 0