SyntaxError:用于test.es5.js的意外令牌'const' [英] SyntaxError: Unexpected token 'const' for testing.es5.js
问题描述
我已切换到 Angular4.0.0-rc.1 , 看来ES5测试包包含ES2015代码.
I've switched to Angular4.0.0-rc.1 and it looks like ES5 testing bundles contain ES2015 code.
我收到此错误:
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
at webpack:///~/@angular/core/@angular/core/testing.es5.js:10:0 <- src/test.ts:16345
还在Angular仓库中发现了相关问题.
Also found related issue on Angular repo.
推荐答案
我刚刚创建了一个基本的Angular项目,并且在PhantomJS集成中存在相同(或相似)的问题.
I just created a basic Angular project and had the same (or similar) issue with PhantomJS integration.
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
at webpack:///src/app/app.component.ts:1:0 <- src/test.ts:63184
我们的团队成功了,这就是我们在文档中所扔的东西:
PhantomJS是可用于自动化测试的无头(又称无GUI)浏览器. 当前,PhantomJS有一个局限性,因为它仅支持
Our team got it to work and here's what we tossed in our documentation:
PhantomJS is a headless (aka, no GUI) browser that can be used for automated testing. Currently, PhantomJS has a limitation in that it only supports the ES5 standard.
-
npm install -g phantomjs-prebuilt
-
npm install --save-dev karma-phantomjs-launcher
- 在karma.conf.js中
npm install -g phantomjs-prebuilt
npm install --save-dev karma-phantomjs-launcher
- in karma.conf.js
- 在插件部分添加
require('karma-phantomjs-launcher')
- 将
PhantomJS
添加到浏览器
- add
require('karma-phantomjs-launcher')
to the plugins section - add
PhantomJS
to the browsers
-
src/polyfill.ts中的
- in src/polyfill.ts
- 添加
import 'intl';
(在底部取消注释) - 在常绿需求部分添加
import "core-js/client/shim";
- add
import 'intl';
(uncomment at the bottom) - add
import "core-js/client/shim";
to the Evergreen requirements section
- 将目标设置为
es5
.
假设一切顺利,测试应该可以进行.
Assuming all goes well, testing should work.
有关如何触发测试运行的一些示例:
Some examples on how to trigger a test run:
-
ng test --browsers PhantomJS --singleRun true
-
./node_modules/karma/bin/karma start ./karma.conf.js --browsers PhantomJS --singleRun true
ng test --browsers PhantomJS --singleRun true
./node_modules/karma/bin/karma start ./karma.conf.js --browsers PhantomJS --singleRun true
这篇关于SyntaxError:用于test.es5.js的意外令牌'const'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!