2.1.1 • Published 7 years ago
boar-angular2-testing v2.1.1
Boar Angular2 Testing
This is an angular2 test helper collection.
Install
npm install --save-dev boar-angular2-testingHow to provide
import { SyncMockBackend } from 'boar-angular2-testing';
beforEachProvider(() => {
SyncMockBackend,
provide(Http, {
useFactory: (backend, defaultOptions) => {
return new Http(backend, defaultOptions);
},
deps: [SyncMockBackend, BaseRequestOptions]
})
});Manual flush
const backend = new SyncMockBackend();
backend
.whenGET('http://test.me/api/templates/abc123')
.respondWithSuccess({ _id: 5, name: 'Test template' });
backend
.whenDELETE('http://test.me/api/templates/abc123')
.respondWithError('Something went wrong!'));
service.load();
backend.flushNext();
service.delete();
backend.flushNext();Auto flush
const backend = new SyncMockBackend({ autoRespond: true });
backend
.whenGET('http://test.me/api/templates/abc123')
.respondWithSuccess({ _id: 5, name: 'Test template' });
service.load();Verify No Pending Requests
const backend = new SyncMockBackend();
backend
.whenGET('http://test.me/api/templates/abc123')
.respondWithSuccess({ _id: 5, name: 'Test template' });
service.load();
//backend.flushNext();
backend.verifyNoPendingRequests();It will throw an error because there is an unflushed request.
Verify No Expected Requests
const backend = new SyncMockBackend();
backend
.whenGET('http://test.me/api/templates/abc123')
.respondWithSuccess({ _id: 5, name: 'Test template' });
backend
.whenDELETE('http://test.me/api/templates/abc123')
.respondWithSuccess({ _id: 5, name: 'Test template' });
service.load();
//backend.delete();
backend.verifyNoExpectedRequests();It will throw an error because there is an unused expectation. (DELETE)
2.1.1
7 years ago
2.1.0
8 years ago
2.0.1
10 years ago
2.0.0
10 years ago
1.8.0
10 years ago
1.7.2
10 years ago
1.7.1
10 years ago
1.7.0
10 years ago
1.6.0
10 years ago
1.5.1
10 years ago
1.5.0
10 years ago
1.4.0
10 years ago
1.3.0
10 years ago
1.2.0
10 years ago
1.1.3
10 years ago
1.1.2
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago