unit-testing - Web 组件测试器中未定义聚合物
问题描述
我正在尝试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 中的函数
如何防止这种情况并运行适当的单元测试?
解决方案
推荐阅读
- python - Python Networkx 标签易读性问题 - 市场篮分析
- c++ - 当在蛇游戏中打印障碍物时,如何解决边框问题?
- email - 如何在 magento 管理面板中添加谷歌字体 API
- ansible - 有没有更好的方法来重组没有“include_tasks”的剧本并同时运行任务?
- php - 只需尝试在 PHP 中使用多个变量。($Var * 0.75)
- excel - 如何在保留格式的同时将表格从 Word 复制到 Excel
- r - 基于两列修改R数据框
- python - 想要使用 groupby 和 transform 创建具有唯一值列表的列
- javascript - 什么是简洁而优雅的方式来表达“这个数字或零,以较高者为准”?
- mysql - Python中的MySQL问题