Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testem #181

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reactions/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var VariableReaction = Reaction.extend({
},

init: function(next) {
this.setFrom(this.variableName);
next();
this.setFrom(this.variableName);
},

observe: function() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"jsdom": "0.5.x",
"expect.js": "0.x.x",
"test-things": "git+ssh://[email protected]/Amicus/test-things.git",
"awesome-docs": "git+ssh://[email protected]/Amicus/awesome-docs.git",
"grunt": "~0.4.1",
"grunt-simple-mocha": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"browserify": "~2.35.0",
"grunt-browserify": "~1.2.9",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-jshint": "~0.7.1"
"grunt-contrib-jshint": "~0.7.1",
"brfs": "0.0.8"
}
}
12 changes: 3 additions & 9 deletions test/deprecated/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ var expect = require("expect.js"),

describe("A template with partials", function() {
it("should do collections", function() {
var templates = [
"/templates/partials.html",
"/templates/embedded_partial.html",
"/templates/list_item.html"
];

var model = {
items: new Backbone.Collection([{ variable: "wat1" }, { variable: "wat2" }]),
thing: new Backbone.Model({ name: "Zach" })
};

_(templates).each(function(template) {
EndDash.templateStore.load(template, fs.readFileSync(__dirname + template).toString());
});
EndDash.templateStore.load("/templates/partials.html", fs.readFileSync(__dirname + "/templates/partials.html").toString());
EndDash.templateStore.load("/templates/embedded_partial.html", fs.readFileSync(__dirname + "/templates/embedded_partial.html").toString());
EndDash.templateStore.load("/templates/list_item.html", fs.readFileSync(__dirname + "/templates/list_item.html").toString());

var template = generateTemplate(model, '/templates/partials.html');

Expand Down
29 changes: 14 additions & 15 deletions test/form_binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ describe("when the template has an input", function() {
expect($("input:nth-child(2)").is(":checked")).to.be(true);
});
});
describe("when the template has a select input", function() {
it("should update the model when it changes to it's change");
var originalTestFunctionForWhenNotPending = function() {
var model = new Backbone.Model({ val: "2" }),
markup = '<div class="model-"><select class="val-">' +
'<option id="opt1" value="1">1</option>' +
'<option id="opt2" value="2">2</option>' +
'</select></div>',
template = generateTemplate({ model: model }, markup);

expect(model.get("val")).to.be("2");
$("#opt1").click();
expect(model.get("val")).to.be("1");
};
});
//describe("when the template has a select input", function() {
// var originalTestFunctionForWhenNotPending = function() {
// var model = new Backbone.Model({ val: "2" }),
// markup = '<div class="model-"><select class="val-">' +
// '<option id="opt1" value="1">1</option>' +
// '<option id="opt2" value="2">2</option>' +
// '</select></div>',
// template = generateTemplate({ model: model }, markup);
//
// expect(model.get("val")).to.be("2");
// $("#opt1").click();
// expect(model.get("val")).to.be("1");
// };
//});
28 changes: 14 additions & 14 deletions test/looping.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ describe("A template with looping after scoping", function(){
new Backbone.Model({ type: "cool" })
];
this.topLevelObject = new Backbone.Model({ things: this.things });
this.markup = "<div class='things-'>" +
"<div data-each>" +
"<div>" +
"<div class=type-'>" +
"</div>" +
"</div>" +
"</div>" +
"</div>";
this.markup = '<div class="things-">' +
'<div data-each>' +
'<div>' +
'<div class="type-">' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
this.template = generateTemplate(this.topLevelObject, this.markup);
});
it("looping will change when an object types change", function(){
Expand Down Expand Up @@ -174,12 +174,12 @@ describe("A template with looping and scoping on the same element", function(){

describe("A template with no looping and no scoping", function(){
beforeEach(function(){
this.markup = "<div data-each>" +
"<div>" +
"<div class=type-'>" +
"</div>" +
"</div>" +
"</div>";
this.markup = '<div data-each>' +
'<div>' +
'<div class="type-">' +
'</div>' +
'</div>' +
'</div>';
});
describe("bound to an array literal containing backbone models", function(){
beforeEach(function(){
Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
--require expect.js
--compilers docjs:awesome-docs,markdown:awesome-docs,md:awesome-docs
--ui bdd
--globals window,$
--recursive
Expand Down
45 changes: 0 additions & 45 deletions test/non_backbone_integration.js
Original file line number Diff line number Diff line change
@@ -1,46 +1 @@
var expect = require('expect.js'),
createBrowser = require('./support/create_browser');

describe('With an existing backbone', function() {
var context;

before(function(done) {
createBrowser({
scripts: [
__dirname + '/../vendor/jquery.js',
__dirname + '/../vendor/underscore.js',
__dirname + '/../vendor/backbone.js',
__dirname + '/../build/end-dash.js'
]
}, function(errors, _context) {
context = _context;
done(errors);
});
});

it('defers to window.Backbone', function() {
expect(context.EndDash.Backbone).to.be(context.Backbone);
});
});

describe('Without an existing backbone', function() {
var context;

before(function(done) {
createBrowser({
scripts: [
__dirname + '/../vendor/jquery.js',
__dirname + '/../vendor/underscore.js',
__dirname + '/../build/end-dash.js'
]
}, function(errors, _context) {
context = _context;
done(errors);
});
});

it('loads its own Backbone', function() {
expect(context.Backbone).to.not.be.ok();
expect(context.EndDash.Backbone).to.be.ok();
});
});
11 changes: 3 additions & 8 deletions test/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ var expect = require("expect.js"),

describe("A template with partials", function() {
it("should do collections", function() {
var templates = [
"/support/templates/partials.html",
"/support/templates/embedded_partial.html",
"/support/templates/list_item.html"
];

var model = {
items: new Backbone.Collection([{ variable: "wat1" }, { variable: "wat2" }]),
thing: new Backbone.Model({ name: "Zach" })
};

_(templates).each(function(template) {
EndDash.registerTemplate(template, fs.readFileSync(__dirname + template).toString());
});
EndDash.templateStore.load("/support/templates/partials.html", fs.readFileSync(__dirname + "/support/templates/partials.html").toString());
EndDash.templateStore.load("/support/templates/embedded_partial.html", fs.readFileSync(__dirname + "/support/templates/embedded_partial.html").toString());
EndDash.templateStore.load("/support/templates/list_item.html", fs.readFileSync(__dirname + "/support/templates/list_item.html").toString());

var template = generateTemplate(model, '/support/templates/partials.html');

Expand Down
32 changes: 32 additions & 0 deletions test/select_tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require('./support/helper');

var expect = require("expect.js"),
generateTemplate = require("./support/generate_template"),
Backbone = require('../lib/end-dash').Backbone;

require("../lib/template");

describe("Setting a single variable", function() {
before(function() {
this.markup = '<div>' +
' <select class="number-">' +
' <optgroup data-scope="/numbers" data-each>' +
' <option value="#{num}" class="word-"></option>' +
' </optgroup>' +
' </select>' +
'</div>'
})


it("should be set in the html", function () {
var numbers = new Backbone.Collection([
{ num: 1, word: 'one' },
{ num: 2, word: 'two' },
{ num: 3, word: 'three' }
])
var template = generateTemplate({ number: 2, numbers: numbers }, this.markup);

expect($('.number-').val()).to.equal('2')
});

});
4 changes: 2 additions & 2 deletions test/stop_observing.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ describe("When I clean up a template", function() {

it("should not remove other peoples listeners from the element", function(done) {
var model = { person: new Model({ name: "zach" }) },
markup = '<div class="person-"><input class="name-"></div>',
markup = '<div class="person-"><input class="name-" /></div>',
template = generateTemplate(model, markup);


$(".name-").on("change", function() {
$(".name-").one("change", function() {
done();
});

Expand Down
35 changes: 18 additions & 17 deletions test/support/create_browser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var jsdom = require('jsdom'),
_ = require('underscore');

module.exports = function(config, done) {
config = _.extend({
done: done,
html: '<html><head></head><body></body></html>',

features: {
FetchExternalResources: ['script'],
ProcessExternalResources: ['script'],
MutationEvents: ['1.0']
}
}, config);

jsdom.env(config);
};
//var jsdom = require('jsdom'),
// _ = require('underscore');
//
//module.exports = function(config, done) {
// config = _.extend({
// done: done,
// html: '<html><head></head><body></body></html>',
//
// features: {
// FetchExternalResources: ['script'],
// ProcessExternalResources: ['script'],
// MutationEvents: ['1.0']
// }
// }, config);
//
// jsdom.env(config);
//};
module.exports = function() {}
27 changes: 14 additions & 13 deletions test/support/helper.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var createBrowser = require('./create_browser');

before(function(done) {
require('../../lib/end-dash');

createBrowser({
scripts: [__dirname + '/../../vendor/jquery.js']
}, function(errors, _context) {
global.window = _context;
global.$ = window.$;
done();
});
});
window.$ = require('jquery-browserify')
//var createBrowser = require('./create_browser');
//
//before(function(done) {
// require('../../lib/end-dash');
//
// createBrowser({
// scripts: [__dirname + '/../../vendor/jquery.js']
// }, function(errors, _context) {
// global.window = _context;
// global.$ = window.$;
// done();
// });
//});
2 changes: 1 addition & 1 deletion test/support/templates/complex_markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div id="navigation">
<ol class="navigation primary">
<li class="logo">
<a href="/"><img alt="Logo" src="/assets/logo.png" /></a>
<a href="/"><img alt="Logo" /></a>
</li>
<li class="active"><a href="/dashboard">Dashboard</a></li>
<li><a href="/users/50b3c832f273e64253000046/potential_associations">Friends</a></li>
Expand Down
12 changes: 12 additions & 0 deletions testem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"framework": "mocha",
"before_tests": "browserify -t brfs test/*.js -o build/test-build.js && browserify -t brfs test/deprecated/*.js -o build/deprecated-test-build.js",
"serve_files": [
"build/test-build.js",
"build/deprecated-test-build.js"
],
"src_files": [
"test/**/*.js",
"lib/**/*.js"
]
}