boar-angular2-testing
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

Boar Angular2 Testing

This is an angular2 test helper collection.

Install

npm install --save-dev boar-angular2-testing

How 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)

Readme

Keywords

none

Package Sidebar

Install

npm i boar-angular2-testing

Weekly Downloads

9

Version

2.1.1

License

MIT

Unpacked Size

50.5 kB

Total Files

34

Last publish

Collaborators

  • emarsys-deployer
  • sviktor