【发布时间】:2015-06-03 19:08:52
【问题描述】:
我的路线定义如下
app.post '/v1/media', authentication.hasValidApiKey, multipart, mediaController.create, mediaController.get
我想为路线的各个组件编写测试。所以从authentication.hasValidApiKey开始,这是在另一个文件中定义的函数:
exports.hasTokenOrApi = (req, res, next) ->
if not req.headers.authorization
return res.status(403).end()
doOtherStuff...
在我的测试中,我有:
authentication = require '../src/middlewares/authentication'
describe 'Authentication Middleware', ->
before (done) ->
done()
it 'should check for authentication', (done) ->
mock_req = null
mock_res = null
mock_next = null
authentication.hasTokenOrApi mock_res, mock_req, mock_next
done()
如何处理 req、res 和 next?以及如何设置代码覆盖率以运行?我正在运行我的测试:export NODE_ENV=test && ./node_modules/.bin/mocha --compilers coffee:'./node_modules/coffee-script/lib/coffee-script/register'
【问题讨论】:
-
我不相信
supertest会让我获得代码覆盖率,是吗?
标签: node.js unit-testing express coffeescript mocha.js