多次我按照这个教程用于测试的角度2应用程序:https://angular.io/docs/ts/latest/guide/testing.html角2打字稿应用测试 - 规格出现在茉莉
与First app test
部分完成后,前往unit-tests.html
我看到我出现多个规格报告时间:
虽然我还没有做出任何改变教程代码,对于快速参考,这里是我单位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)没有三倍的结果。所以不仅仅是所有的结果都是三倍的,只是一些。我猜这与事物的挑剔时机有关,例如简单测试完成的时间与需要其他更多复杂测试(其他下载?)的时间完成相对比,例如,当浏览器窗口完成加载并重新启动茉莉花时。 –