6.0.0 • Published 6 years ago

rxrest-assert v6.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

RxRest Assert Build Status

Assertion library for RxRest.

npm install rxrest-assert --save-dev

Example

const {RxRestAssert} = require('rxrest-assert')
const assert = new RxRestAssert(new RxRestConfiguration())

assert.expectGET('foo')
.respond({foo: 'bar', id: 1})

rxrest.one('foo')
.post()
.then(e => {

})
.catch(e => {
  console.log(e.message) //Method should be "GET", got "POST"
})

API

The API is inspired by the angular $httpBackend service.

Expect

Expectations must respect requests order.

expect(method, url, [request])

Parameters

ParamTypeDetails
methodstringHTTP method
urlstring or RegExpHTTP url or RegExp to match requested url
requestRequestThe expected Request. It's url query params or headers will be tested against the request

For example, to match headers and query parameters:

let headers = new Headers()
headers.set('Authorization', 'Bearer foo')

assert.expect('GET', 'foo', new Request('foo?test=foobar', {headers: headers})

rxrest
.one('foo')
.get({test: 'foobar'}, {'Authorization': 'Bearer foo'})
.then(e => {})
.catch(e => {})

Returns

Returns an object with a respond method:

respond(response: Response|Object|number)
  • If the response is an Object it'll be the response body (json encoded).
  • If it's a number, it will be the reponse status
  • If it's a Response instance, it's taken as is

Aliases

expectGET(url, request)
expectPOST(url, request)
expectPUT(url, request)
expectHEAD(url, request)
expectPATCH(url, request)
expectDELETE(url, request)

When

When doesn't depend on the requests order and it's signature is {method, url}.

The API is the same as expect:

when(method, url, [request])

Aliases

whenGET(url, request)
whenPOST(url, request)
whenPUT(url, request)
whenHEAD(url, request)
whenPATCH(url, request)
whenDELETE(url, request)
6.0.0

6 years ago

5.0.0

6 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

2.0.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago