Ecmascript 6 ES6:测试在浏览器中通过,在phantomJS中失败,“找不到变量:反射”
我正在为js库重写ES6Ecmascript 6 ES6:测试在浏览器中通过,在phantomJS中失败,“找不到变量:反射”,ecmascript-6,phantomjs,qunit,Ecmascript 6,Phantomjs,Qunit,我正在为js库重写ES6 class VerbalExpression extends RegExp { // snipped for brevity } /** * Alias for the constructor * @return {VerbalExpression} new instance of VerbalExpression */ function instantiate() { return new VerbalExpression(); } // U
class VerbalExpression extends RegExp {
// snipped for brevity
}
/**
* Alias for the constructor
* @return {VerbalExpression} new instance of VerbalExpression
*/
function instantiate() {
return new VerbalExpression();
}
// UMD (Universal Module Definition)
// https://github.com/umdjs/umd
if (typeof module !== 'undefined' && module.exports) { // CommonJS
module.exports = instantiate;
} else if (typeof define === 'function' && define.amd) { // AMD Module
define('VerEx', [], () => VerbalExpression);
} else { // Browser
this.VerEx = instantiate;
}
当我在浏览器中运行测试时,它们都通过了
但是,当我在终端中运行测试时,会出现错误
❯ npm test
verbal-expressions@0.3.0 test /Users/shreyasminocha/dev/open source/JSVerbalExpressions
grunt test
Running "qunit:files" (qunit) task
Testing test/index.html FFFFFFFFFFFFFFFFFFFF
>> something
>> Message: Died on test #1 global code@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:7:5: Can't find variable: Reflect
>> Actual: null
>> Expected: undefined
>> ExtendableBuiltin@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:11:31
>> VerbalExpression@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:59:130
>> instantiate@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:588:32
>> somethingTest@file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:8:26
...
Warning: 20 tests completed with 20 failed, 0 skipped, and 0 todo.
20 assertions (in 91ms), passed: 0, failed: 20 Use --force to continue.
注意:我正在编译的es6代码上运行测试,也就是说,我在运行测试之前运行babel
我猜这与幻影有关。我如何在终端通过测试?我错过什么了吗?有什么解决办法吗?稳定的PhantomJS不支持ES6,也不再处于开发阶段,如果可能的话,迁移到PhantomJS的灵感来源于它。我如何使用Puppeter with grunt运行Qunit测试?对不起,我总是想当然地访问Google。。。这有帮助吗?