本文整理汇总了TypeScript中@angular/common/http/testing.HttpTestingController.match方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpTestingController.match方法的具体用法?TypeScript HttpTestingController.match怎么用?TypeScript HttpTestingController.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common/http/testing.HttpTestingController
的用法示例。
在下文中一共展示了HttpTestingController.match方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should see if rates are available', () => {
service.updateRatesBtc().then(() => {
expect(service.isBtcAvailable()).toBe(true);
});
httpMock.match(btcUrl)[1].flush(btcResponse);
httpMock.match(bchUrl)[0].flush(bchResponse);
httpMock.verify();
});
示例2: it
it('can test multiple requests', () => {
let testData: Data[] = [
{ name: 'bob' }, { name: 'carol' },
{ name: 'ted' }, { name: 'alice' }
];
// Make three requests in a row
httpClient.get<Data[]>(testUrl)
.subscribe(d => expect(d.length).toEqual(0, 'should have no data'));
httpClient.get<Data[]>(testUrl)
.subscribe(d => expect(d).toEqual([testData[0]], 'should be one element array'));
httpClient.get<Data[]>(testUrl)
.subscribe(d => expect(d).toEqual(testData, 'should be expected data'));
// get all pending requests that match the given URL
const requests = httpTestingController.match(testUrl);
expect(requests.length).toEqual(3);
// Respond to each request with different results
requests[0].flush([]);
requests[1].flush([testData[0]]);
requests[2].flush(testData);
});
示例3: it
it('should match', () => {
service.get(url).subscribe();
backend.match((request) => {
return request.url.match(/posts/) &&
request.method === 'GET';
});
backend.verify();
});
示例4: it
it('init', () => {
authenticationService.init();
authenticationService.onLoginEvent.getValue();
const req = mockBackend.match('/api/v1/user');
req[1].flush('user');
expect(req[1].request.method).toBe('GET');
expect(authenticationService.onLoginEvent.getValue()).toEqual(true);
});