Skip to content

Instantly share code, notes, and snippets.

@fish2000
Created July 14, 2012 19:31
Show Gist options
  • Save fish2000/3112936 to your computer and use it in GitHub Desktop.
Save fish2000/3112936 to your computer and use it in GitHub Desktop.
Mixing Require.js, Jasmine, Sinon.js and Backbone.
## ItemView.coffee in the specs/coffee folder ##
define ["ItemView"], (ItemView) ->
###
Specs for ItemView
###
describe "Item View", ->
###
Common setup and teardown
###
beforeEach ->
# Make a new arbitraty Backbone.Model
@model = new Backbone.Model
id: 1
title: "Sample Todo"
priority: 2
done: false
# And make a view for it.
@view = new ItemView model: @model
###
Rendering tests
###
describe "Rendering", ->
###
Common setup and teardown
###
beforeEach ->
@view.render()
@el = $ @view.el
it "returns the view object", ->
# Check that the render method returns the view
expect( @view.render() ).toEqual @view
require ["model","collection","view","router","etc"], (main,collection,view,router,etc) ->
# Globalize the classes
window.main = main
window.collection = collection
window.view = view
window.router = router
window.etc = etc
# And then run the specs
# ...
jasmineEnv.execute()
# ...
## SpecRunner.js in the specs/js folder ##
define( [
"specs/Item",
"specs/List",
"specs/ItemView",
"specs/ListView",
"specs/Routes",
"specs/MainRouter",
], function(){
return SpecRunner = function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
return jasmineEnv.execute();
}
}
);
// SpecRunner.html //
// ...
$(document).ready( function() {
window.App = {}
// Regular Require.js configuration here.
require.config({
baseUrl: '../build/js', // Leave the baseUrl as in your release build
paths: {
text: 'libs/require/text',
specs: '../../specs/js' // Adding this helps a lot...
}
});
require([
'specs/SpecRunner', // ...as shown here.
],
function(SpecRunner) {
SpecRunner();
}
);
});
// ...
describe "something", ->
it "something else", ->
require ["dep1","dep2","..."], (dep1,dep2,...)->
#expectation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment