我正在尝试对我的angular2应用进行单元测试。简单的测试通过但是当我打开开发人员工具时,我仍然会收到错误“未捕获的ReferenceError:require未定义”的测试.ts.9:。我该如何加载库?那么这个错误会不会出现?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing Jasmine</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>
<script src="../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/router.js"></script>
<script src="../node_modules/angular2/bundles/testing.dev.js"></script>
<script src="../node_modules/angular2/testing.js"></script>
</head>
<body>
<!-- #1. add the system.js library -->
<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('hero.spec.js')
.then(window.onload)
.catch(console.error.bind(console));
</script>
</body>
</html>
答案 0 :(得分:0)
不需要此库。我删除了导入行,没有任何损坏。所以我想这不是真的需要。
<script src="../node_modules/angular2/testing.js"></script>