1.0.0 • Published 8 years ago

spyrr v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

SPY R/R

v1.0.0

Spy on your inner controller processes, create and test actions against server request/response without spinning up a live instance, using the supertest API.

Usage

Import

You can import either via CommonJS or ES6, depending on what you're using.

var mockRequest = require( 'spyrr' );

or, ES6:

import mockRequest from 'spyrr';

Test a request/response, and spy on inner methods

ES5:

var controller = require( './routes/endpoint.js' );

describe( 'POST /endpoint', function() {

    var someTestObject = { test: true };

    beforeEach( function() {

        spyOn( controller.endpoint, 'checkAuthorization' ).and.callFake( function() {

            return false;
        });
    });

    it( 'should reject requests with an invalid auth token', function( done ) {

        mockRequest( controller.endpoint )
            .params( { path: 'testpath', id: 'my-test' } )
            .query( { authToken: 'someInvalidToken' } )
            .body( { someObject: someTestObject } )
            .expect( 'Content-Type', /json/ )
            .expect( 401, {

                    error: true
                }, done 
            )
        ;
    });
});

ES6:

import controller from './routes/endpoint.js';

describe( 'POST /endpoint', () => {

    let someTestObject = { test: true };

    beforeEach( () => {

        spyOn( controller.endpoint, 'checkAuthorization' ).and.callFake( () => {

            return false;
        });
    });

    it( 'should reject requests with an invalid auth token', done => {

        mockRequest( controller.endpoint )
            .params( { path: 'testpath', id: 'my-test' } )
            .query( { authToken: 'someInvalidToken' } )
            .body( { someObject: someTestObject } )
            .expect( 'Content-Type', /json/ )
            .expect( 401, {

                    error: true
                }, done 
            )
        ;
    });
});

Build

Note: there are only minimal tests thus far. More are on the way!

You can build easily with gulp, which will test then build. To just test, run gulp test.

Requirements

Built to work with jasmine, though it may work with other testing frameworks.

Contribute

Please fork the project, then use a pull request to make improvements and fixes. This is very new so there is likely to be many undocumented issues, especially with non-jasmine frameworks.

Authors and Acknowledgements

Written by Rob Porter.

Based upon both supertest and dupertest. Thanks to TJ Holowaychuk and Tyler Olson for these.

License

MIT

1.0.0

8 years ago

0.4.0

8 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago