如何在httpBackend.expectPOST中捕获参数? AngularJS/Typescript/AMD/RequireJS/Jasmine/Karma/Sinon
我有一个AngularJS定制日志服务,它构建了日志消息的私有内部队列。此内部队列仅统计其队列中不属于debug类型的消息。在某个时刻,它会将这个私有队列发送到一个由消息大小限制和前面提到的计数处理的API。这种逻辑也是私有的。我需要捕获http.POST并检查传递给它的对象,以确保在包含所有消息的对象中没有发送调试 这是单元测试,所以我可以访问httpBackEnd,但我不知道如何访问args。我也有jasmine spy的,甚至是sinon的,但我迄今为止尝试过的方法都没有结果如何在httpBackend.expectPOST中捕获参数? AngularJS/Typescript/AMD/RequireJS/Jasmine/Karma/Sinon,angularjs,typescript,jasmine,sinon,httpbackend,Angularjs,Typescript,Jasmine,Sinon,Httpbackend,我有一个AngularJS定制日志服务,它构建了日志消息的私有内部队列。此内部队列仅统计其队列中不属于debug类型的消息。在某个时刻,它会将这个私有队列发送到一个由消息大小限制和前面提到的计数处理的API。这种逻辑也是私有的。我需要捕获http.POST并检查传递给它的对象,以确保在包含所有消息的对象中没有发送调试 这是单元测试,所以我可以访问httpBackEnd,但我不知道如何访问args。我也有jasmine spy的,甚至是sinon的,但我迄今为止尝试过的方法都没有结果 module
module MyLogClass {
export class Logger implements ng.ILogService {
private _currentSize: number = 0;
private _currentBatch: myLoggingType[] = new Array<myLoggingType>();
public totalNumberOfMessages: number = 0;
public includeDebug: boolean = false;
.
.
.
//Overriding all the Angular log functions (public functions)
//Logic for striping out debug messages if needed (private functions)
//Logic for handling when to send in here (private functions)
private SendLogs = () => {
this.http.post('someurl', (this._currentBatch))
.success( (data: any[], status, headers, config) => {
console.log('logs sent');
})
.error( (data: any[], status, headers, config) => {
//error handling call
});
}
}
}
这是一个简短的介绍,描述了我用日志替换Angulars的要点。下面是我试图通过单元测试实现的一些示例代码
beforeEach(angular.mock.inject(function ($http: ng.IHttpService, $httpBackend: ng.IHttpBackendService) {
localService = new MyLogService();
localService.LogHttp = $http;
httpBackend = $httpBackend;
}));
it('should strip Debug messages, then send messages and reset size', () => {
localService.totalNumberOfMessages = 50;
// Fill the Queue, make sure to put in some debug messages.
var i = 0;
// Right here I need to figure out how to catch the data sent to that URL
// The code I'm showing here is for example, I don't know what this expectPOST should look like.
httpBackend.expectPOST('someurl', data).respond('passed');
while (i < 50) {
// generating fake calls to the log service
i++;
}
httpBackend.flush();
// Check the data sent to make sure there were no debug messages in it. Only how?