Javascript 如何在angular 2中编写基本单元测试?
我在官方网站上有以下文件。但在文档中,测试部分已经过时,不能使用当前的angular 2 beta版本。我需要写一个基本测试来检查条件是否正常工作。我怎么能用《天使2》中的茉莉花做到这一点呢 设置jasmine使用angular2(beta.7)运行typescript单元测试:Javascript 如何在angular 2中编写基本单元测试?,javascript,unit-testing,angular,Javascript,Unit Testing,Angular,我在官方网站上有以下文件。但在文档中,测试部分已经过时,不能使用当前的angular 2 beta版本。我需要写一个基本测试来检查条件是否正常工作。我怎么能用《天使2》中的茉莉花做到这一点呢 设置jasmine使用angular2(beta.7)运行typescript单元测试: 设置角度项目 (请参见说明5分钟快速启动) ) Rootdir是我的项目 <html> <head> <title>Angular2: Jasmine Tests</t
(请参见说明5分钟快速启动) ) Rootdir是我的项目
<html>
<head>
<title>Angular2: Jasmine 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.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/app.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>
npm install jasmine-core --save-dev --save-exact
在myproject/typings中创建一个新文件jasmine.d.ts
/// <reference path="jasmine\jasmine.d.ts" />
live-server --open=unit-test.html
typings install jasmine --save-dev --ambient
现在angular已经有了关于angular 2单元测试和使用jasmine和karma的端到端测试的良好文档。它有解释它使用的例子,非常容易理解和遵循
参考资料:您能发布您尝试过的内容和失败的地方吗?有任何错误消息吗?我会尝试这个,如果它工作,我会接受答案。
typings install jasmine --save-dev --ambient