Skip to content

A testing helper for Ember that lets you control the XHR request/response cycle

Notifications You must be signed in to change notification settings

zeppelin/ember-testing-httpRespond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Ember.Test.httpRespond helper

Adds a httpRespond helper to Ember.Test for integration testing. This helper chains a promise and allows you to control where in the flow of execution an http response is emitted.

This makes it easy to test sitautons like:

  • Loading screens
  • Button disabling while requests process
  • Multiple requests to the same url
  • The effect of multiple simultaneous requests that complete in a specifc order

Using HTTP response emitting instead of the fixture feature of Ember Data or Ember Model ensures that the entire stack of your Ember.js application is exercised during integration testing.

Example

module("commenting on a post", function(){
  setup: function(){
    fakehr.start();
  },
  teardown: function(){
    fakehr.reset();
  }
});

test("people can browse to a post and leave a comment", function(){
  var comment = "I agree, Tom's hair does smell like newly fallen Portland rain."

  visit("/articles")
  .then(function(){
    equal(find(".loading-screen").length, 1);
  })
  .httpRespond("get", "/api/articles", [{id: 1, body: '...'}, {id: 2, body: '...'}])
  .then(function(){
    equal(find(".loading-screen").length, 0);
  })
  .click(".article:first")
  .fillIn(".comment-box", comment)
  .click(".comment-submit")
  .then(function(){
    equal(find(".spinner").length, 1);
  })
  .httpRespond("post", "/api/articles/1/comments", {id: 1, body: comment})
  .then(function(){
    equal(find(".comment:contains('%@')".fmt(comment)).length, 1);
  });
});

Dependencies

httpRespond depends on fakehr and FakeXMLHttpRequest. Until we live in the rosy future of standardized module and package systems, obtain both from github and load them as part of your test suite.

About

A testing helper for Ember that lets you control the XHR request/response cycle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published