ES6:测试在浏览器中传递,使用phantomJS失败,“无法找到变量:反映”

时间:2017-12-12 06:35:13

标签: 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();
}

// 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;
}

当我在浏览器中运行测试时,它们都会通过。

tests pass in browser

但是,当我在终端中运行测试时,我会收到错误。

❯ 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有关。如何让测试通过终端?我错过了什么吗?任何解决方法?

1 个答案:

答案 0 :(得分:1)

稳定的PhantomJS不支持ES6,不再开发,如果可能的话,请迁移到受{PhantomJS启发的puppeteer