GithubHelp home page GithubHelp logo

superjest's Introduction

superjest

A set of Hamjest matchers for user with superagent

Usage

superagent and hamjest are peer dependencies, so users of superjest need to install those modules too.

$ npm install superagent hamjest superjest

Using with superagent

Perform the assertions at the end of the request, however you like to user superagent.

it("requests google homepage", function(done) {
  superagent
   .get("https://www.google.com")
   .end((err, resp) => {
     assertThat(resp, hasStatusCode(200));
 
     done();
   });
 });

Matchers

For examples of the Matchers in action, see the tests.

hasStatusCode

  • @param {number} code

Assert that the response has the correct status code.

assertThat(resp, hasStatusCode(200));

hasHeader

  • @param {string} name The header name
  • @param {Matcher} [matcher] Optional matcher for the header value

Assert that the response has a header, and that header matches expectations.

assertThat(resp, hasHeader('etag'));
assertThat(resp, hasHeader('content-type', equalTo('text/plain')));

hasContentType

  • @param {Matcher} matcher

Assert that the response has the correct content type header.

Ignores field parameters

assertThat(resp, hasContentType(equalTo(json())));
assertThat(resp, hasContentType(equalTo("text/xml")));

hasCharset

  • @param {Matcher} matcher

Assert that the response has the correct charset.

The charset must be specified with a '-'

assertThat(resp, hasCharset(equalTo("utf-8")));

hasContentLength

  • @param {Matcher} matcher

Assert that the response has the correct content length header.

assertThat(resp, hasContentLength(equalTo(12)));

hasLocation

  • @param {Matcher} matcher

Assert that the response has the correct location header.

assertThat(resp, hasLocation(equalTo("http://www.google.com")));

isRedirectedTo

  • @param {string} location

Convenience to assertion redirection

assertThat(resp, isRedirectedTo("http://www.google.com"));

html

Convenience to return 'text/html' MIME type

json

Convenience to return 'application/json' MIME type

text

Convenience to return 'text/plain' MIME type

Thanks

This library was inspired by chai-http. I just prefer to use hamjest

License

MIT

superjest's People

Contributors

kierans avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.