Created
September 17, 2012 15:49
-
-
Save theycallmeswift/3738126 to your computer and use it in GitHub Desktop.
Full Stack Integration Testing in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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