我目前正在尝试为我正在研究的一个小型 NodeJS API 设置一个单元测试环境。这个 API 是用 ES6 编写的,它使用 express 来处理请求。
到目前为止,我使用的测试结构是:
- 业力
- 茉莉花
- 业力-webpack
- 通天塔装载机
它适用于我的大多数规格。
问题是当我尝试为路由器(来自 Express)编写规范时,我收到以下错误:
SyntaxError: Cannot declare a parameter named 'error' in strict mode
这些是我正在使用的文件:
业力.conf.js
module.exports = function(config) {
config.set({
browsers: ['PhantomJS'],
files: [{
pattern: './src/**/*.spec.js',
watched: false
},
'node_modules/babel-polyfill/dist/polyfill.js'
],
reporters: ['dots', 'growl'],
frameworks: ['jasmine'],
preprocessors: {
'./src/**/*.js': ['webpack']
},
webpack: {
target: 'node',
module: {
loaders: [{
test: /\.js/,
exclude: /node_modules/,
loader: "babel-loader"
}, {
test: /\.json$/,
loader: "json-loader"
}]
},
resolve: {
extensions: ['', '.js', '.json']
},
watch: true
},
webpackServer: {
noInfo: true,
stats: 'errors-only'
}
});
};
authRouter.js
import {Router} from 'express';
export class AuthRouter {
constructor() {
this.router = Router();
this.init();
}
init() {
this.router.post('/login', this.login);
this.router.get('/logout', this.logout);
}
login(req, res){
//Do stuff
}
logout(req, res){
// Do stuff
}
}
const authRoutes = new AuthRouter();
authRoutes.init();
export default authRoutes.router;
authRouter.spec.js
import {AuthRouter} from './AuthRouter';
describe('AuthRouter', () => {
let router;
beforeEach(() => {
router = new AuthRouter();
});
it('work this test :(', () => {
expect(true).toBe(true)
});
});
有人能帮我吗?
提前致谢