Giter VIP home page Giter VIP logo

frisby's Introduction

Frisby

NPM Build Status

A node.js NPM module that makes testing API endpoints easy, fast and fun.

Installation

Install Frisby from NPM:

npm install frisby

Creating Tests

Frisby tests start with frisby.create with a description of the test followed by one of get, post, put, delete, head, or options and ending with run to generate the resulting jasmine spec test. There is a expectStatus method built in to more easily test HTTP status codes. Any other jasmine expect tests should be done inside the after callback.

Each set of unique sequences or API endpoint tests should be started with new frisby.toss method calls instead of trying to chain multiple HTTP requests together.

var frisby = require('frisby');

var URL = 'http://localhost:3000/';
var URL_AUTH = 'http://username:password@localhost:3000/';

frisby.globalSetup({ // globalSetup is for ALL requests
  request: {
    headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' }
  }
});

frisby.create('GET user johndoe')
  .get(URL + '/users/3.json')
  .expectStatus(200)
  .expectJSONTypes({
    id: Number,
    username: String,
    is_admin: Boolean
  })
  .expectJSON({
    id: 3,
    username: 'johndoe',
    is_admin: false
  })
  // 'afterJSON' automatically parses response body as JSON and passes it as an argument
  .afterJSON(function(user) {
  	// You can use any normal jasmine-style assertions here
  	expect(1+1).toEqual(2);

  	// Use data from previous result in next test
    frisby.create('Update user')
      .put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']})
      .expectStatus(200)
    .toss();
  })
.toss();

Any of the Jasmine matchers can be used inside the after and afterJSON callbacks to perform additional or custom tests on the response data.

To run only one of the tests, replace toss to ttoss.

Running Tests

Frisby is built on top of the jasmine BDD spec framework, and uses the excellent jasmine-node test runner to run spec tests in a specified target directory.

File naming conventions

Files must end with spec.js to run with jasmine-node.

Suggested file naming is to append the filename with _spec, like mytests_spec.js and moretests_spec.js

Install jasmine-node

npm install -g jasmine-node

Run it from the CLI

cd your/project
jasmine-node .

Documentation

Documentation is hosted at frisbyjs.com, the documentation pages has separate repositiory.

License

Licensed under the MIT/BSD license.

frisby's People

Contributors

vlucas avatar kmorey avatar marcin-wosinek avatar ericboehs avatar m0x72 avatar cjsaylor avatar donatj avatar sudodoki avatar extronics avatar dbashford avatar danactive avatar valentinh avatar jturmel avatar davewid avatar sasikanth avatar marcoscarceles avatar kreutter avatar derekhe avatar darrenxyli-aa avatar tleyden avatar rblu avatar petrjasek avatar loris avatar nodesocket avatar vance avatar iameugenejo avatar nederdirk avatar dshafik avatar cllunsford avatar cboden avatar

Watchers

James Cloos 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.