Web组件测试器中未定义的聚合物

时间:2018-09-24 17:11:38

标签: unit-testing polymer-2.x web-component-tester

我试图在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个测试失败,在测试函数之外抛出错误:document.getElementById(...)。create不是一个函数      在shop-home.html:25

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

0 个答案:

没有答案