Skip to content

Instantly share code, notes, and snippets.

@terrancesnyder
Forked from clarkdave/vows-phantom.js
Created July 18, 2013 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrancesnyder/6029042 to your computer and use it in GitHub Desktop.
Save terrancesnyder/6029042 to your computer and use it in GitHub Desktop.
var phantom = require('phantom'),
vows = require('vows'),
assert = require('assert');
// nesting tests inside phantom callback so we only
// have to create it once
phantom.create(function(ph) {
var get_page_result = function(url, fn, result) {
ph.createPage(function(page) {
page.open(url, function(status) {
if (status != 'success') result(new Error('Could not connect'), null)
else {
page.evaluate(fn, function(r) {
result(null, r)
ph.exit()
})
}
})
})
}
vows.describe('Correct UI state').addBatch({
'pending requests': {
topic: function() {
get_page_result('http://localhost:8081/something', function() {
return document.querySelectorAll('#something .item')
}, this.callback)
},
'is there': function(err, result) {
assert.isNull(err)
assert.isNotNull(result)
}
}
}).run({}, function() {
// kill the phantom object after tests run
ph.exit()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment