Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created September 17, 2012 15:49
Show Gist options
  • Save theycallmeswift/3738126 to your computer and use it in GitHub Desktop.
Save theycallmeswift/3738126 to your computer and use it in GitHub Desktop.
Full Stack Integration Testing in Node.js
it("should list all persons in response", function() {
var response = readFixtures("persons.json");
var options = {};
var view = new PersonsView({
collection: new Persons()
});
view.render();
fakeResponse(response, options, function() {
view.collection.fetch();
});
expect(view.$('.persons li').length).toEqual(20);
});
browser = new Browser()
fakeAPIResponse('/persons', readFixtures("persons.json"));
browser.visit("http://localhost:3000/", function () {
assert.ok(browser.success);
assert.lengthOf(browser.queryAll(".persons li"), 20);
});
Feature: viewing a list of persons
In order to figure out who is awesome
As a visitor
I want to see a list of awesome persons
Scenario: viewing a list of persons
Given "/api/v1/users" returns the following JSON response:
"""
[{"name": "swift"}, {"name": "john"}]
"""
When I visit the home page
Then I should see 2 persons
sharedSteps = module.exports = ->
@World = require("../support/world").World
@When /^I visit the home page$/, (next) ->
@visit "/", next
@Then /^I should see (\d+) persons$/, (count, next) ->
persons = @browser.queryAll(".persons li")
assert.lengthOf(persons, 2)
next()
@Given /^"([^"]*)" returns the following JSON response:$/, (url, response, next) ->
@mock.get(url).reply(200, JSON.parse(response))
next()
@After "@API", (next) ->
@mock.done()
next()
var app = require('../../app')
, zombie = require('zombie')
, nock = require('nock');
function World(callback) {
this.browser = new zombie.Browser();
this.visit = function(url, callback) {
this.browser.visit(url, callback);
};
this.mock = nock("http://localhost:3000", {allowUnmocked: true});
callback();
};
exports.World = World;
$(function() {
/* ... */
var AppView = Backbone.View.extend({
el: $("#myapp"),
initialize: function() {
var view = new PersonsView({
collection: new Persons()
});
view.collection.fetch();
},
/* ... */
});
var App = new AppView;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment