2016-05-25 33 views
0

我不明白这个错误。为什么我不能使用import在流星测试中不能使用导入

import { chai } from 'meteor/practicalmeteor:chai'; 
^^^^^^ 
SyntaxError: Unexpected reserved word 

package.js

Package.onTest(function(api) { 
    api.use('practicalmeteor:mocha'); 

    api.addFiles('tests/test.js'); 
}); 

test.js

import { chai } from 'meteor/practicalmeteor:chai'; 

describe('Array', function() { 
    describe('#indexOf()', function() { 
     it('should return -1 when the value is not present', function() { 
      chai.assert.equal(-1, [1,2,3].indexOf(5)); 
      chai.assert.equal(-1, [1,2,3].indexOf(0)); 
     }); 
    }); 
}); 
+0

当您使用ES5编译器而不是Meteor使用的ES6编译器时,通常会发生此错误。 – AlexCatch

+0

@AlexCatch我如何改变这种情况?我没有选择es5,我正在使用Meteor 1.3 – user3142695

+0

你在使用什么IDE? – AlexCatch

回答

0

一般来说,这表明(因为它似乎在这里)你不包括ECMAScript的包in yourTest ..

Package.onTest(function(api) { 
    api.use('ecmascript'); 
    api.use('practicalmeteor:mocha'); 

    api.addFiles('tests/test.js'); 
});