【发布时间】:2016-08-13 20:53:04
【问题描述】:
我已按照本教程测试 Angular 2 应用程序:https://angular.io/docs/ts/latest/guide/testing.html
在完成First app test 部分并转到unit-tests.html 后,我看到我的规范报告多次出现:
虽然我没有对教程代码进行任何更改,但这里是我的 unit-tests.html 的快速参考:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Ng App Unit Tests</title>
<link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
</head>
<body>
<!-- #1. add the system.js library -->
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script>
// #2. Configure systemjs to use the .js extension
// for imports from the app folder
System.config({
packages: {
'app': {defaultExtension: 'js'}
}
});
// #3. Import the spec file explicitly
System.import('app/hero.spec')
// #4. wait for all imports to load ...
// then re-execute `window.onload` which
// triggers the Jasmine test-runner start
// or explain what went wrong.
.then(window.onload)
.catch(console.error.bind(console));
</script>
</body>
</html>
hero.spec.ts
import {Hero} from './hero';
describe('Hero', () => {
it('has name', () => {
let hero:Hero = {id: 1, name: 'Super Cat'};
expect(hero.name).toEqual('Super Cat');
});
it('has id', () => {
let hero:Hero = {id: 1, name: 'Super Cat'};
expect(hero.id).toEqual(1);
});
});
知道可能出了什么问题吗?
【问题讨论】:
-
对于 Angular2.0.0-rc.5 的教程,这个问题仍然存在,即 hero.ts 的简单测试的结果增加了三倍。请注意,教程中的下一组测试,即 my-uppercase.pipe.ts,没有三倍的结果。所以不仅仅是所有的结果都增加了两倍,只是一些。我猜这与事情的挑剔时间有关,例如简单测试完成的时间与需要其他内容(其他下载?)的更复杂的测试完成的时间,例如,浏览器窗口完成加载和 jasmine 重新启动的时间。
标签: typescript jasmine angular systemjs