Created
February 12, 2014 05:41
-
-
Save gabeno/8950573 to your computer and use it in GitHub Desktop.
setting up jsdom in nodejs for headless testing
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
'use strict'; | |
var expect = require('chai').expect; | |
var jsdom = require('jsdom'); | |
var jquery = require('jquery'); // option 2 | |
var TodoView = require('../hello-backbone/views/todo-view'); | |
describe('Backbone.View', function() { | |
var $, todoView; // option 1 | |
before(function(done) { | |
jsdom.env({ | |
html: '<html><body></body></html>', | |
scripts: [jquery], // option 2 | |
done: function(err, window) { // this means DOM is ready?! | |
// $ = require('jquery'); // option 1 | |
// | |
todoView = new TodoView(); // => Error: jQuery requires a window with a document | |
done(); | |
} | |
}); | |
}); | |
it('should be tied to a DOM element when created, based off the property provided', function() { | |
expect(todoView.el.tagName.toLowerCase()).to.equal('li'); | |
}); | |
// ... other tests here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@renancarvalho Did you manage to hack it?