Skip to content

Instantly share code, notes, and snippets.

@gabeno
Created February 12, 2014 05:41
Show Gist options
  • Save gabeno/8950573 to your computer and use it in GitHub Desktop.
Save gabeno/8950573 to your computer and use it in GitHub Desktop.
setting up jsdom in nodejs for headless testing
'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
});
@gabeno
Copy link
Author

gabeno commented Jun 23, 2015

@renancarvalho Did you manage to hack it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment