【发布时间】:2014-03-14 12:00:50
【问题描述】:
我正在尝试为带来数据列表的api 编写单元测试。如果用户登录,api 只能被访问。
由于我是单元测试的新手,我不知道该怎么做。以下是我到目前为止尝试的代码。
routes.js
app.get('/api/practices/page/:pagenum', middleware.auth, practices.index);
testpractice.js
describe('Practice Service API to check authentication', function() {
var httpBackend,
serviceUrl = '/api/practices/page/?pagenum=1';
beforeEach(function () {
module('myApp');
inject(function ($httpBackend) {
httpBackend = $httpBackend;
});
});
// check to see if User is Authenticated
it('should have an authenticated user', function() {
// To get response if user is not authenticated
//serviceUrl.expectGET(serviceUrl).respond();
});
});
具体如何做到这一点?
【问题讨论】:
标签: node.js angularjs unit-testing testing