respond-ng
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

respond-ng

Simple Mocking API for Angular 2's Http Service

To use, install respond-ng with npm:

npm install respond-ng --save-dev

Import the providers and Respond:

import HTTP_MOCK_PROVIDERS, {Respond} from 'respond-ng';

Create an injector, then use the injector to get an instance of Respond and the service you are testing:

let respond: Respond, auth: AuthService;
 
beforeEach(function(){
  const injector = Injector.resolveAndCreate([
    HTTP_MOCK_PROVIDERS,
    AuthService
  ]);
 
  respond = injector.get(Respond);
  auth = injector.get(AuthService);
});

Write simple response mocks using Respond's fluent API:

it('should check if the user is authenticated', function(done){
  respond.ok({ authenticated: true }).when.get('/api/authenticated');
 
  auth.check().subscribe((res) => {
    expect(res.authenticated).toBe(true);
    done();
  });
});

After each test, verify there are no outstanding requests:

afterEach(() => respond.verifyComplete());

For more information, see docs for Respond and RequestMatcher. Happy testing!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    3
  • 0.0.1
    1

Package Sidebar

Install

npm i respond-ng

Weekly Downloads

4

Version

0.0.2

License

MIT

Last publish

Collaborators

  • mikeryan52