Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests with RequireJS and noConflict() versions of Underscore.js a…
…nd Backbone.js
- Loading branch information
Showing
6 changed files
with
11,748 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,6 @@ | |||
test: | test: | ||
open tests/test.html | open tests/test.html | ||
open tests/test2.html | |||
|
|
||
minified: | minified: | ||
uglifyjs -o backbone.localStorage-min.js backbone.localStorage.js | uglifyjs -o backbone.localStorage-min.js backbone.localStorage.js |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
<!DOCTYPE HTML> | |||
<html> | |||
<head> | |||
<title>Backbone Test Suite</title> | |||
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" /> | |||
<script type="text/javascript" src="vendor/qunit.js"></script> | |||
|
|||
<script type="text/javascript" data-main="test2" src="vendor/require.js"></script> | |||
</head> | |||
<body> | |||
<h1 id="qunit-header">Backbone Test Suite</h1> | |||
<h2 id="qunit-banner"></h2> | |||
<h2 id="qunit-userAgent"></h2> | |||
<ol id="qunit-tests"></ol> | |||
<br /><br /> | |||
<h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1> | |||
|
|||
<!-- | |||
<div id="jslitmus_container" style="margin: 20px 10px;"></div> | |||
--> | |||
</body> | |||
</html> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
define("backbone-loader", [ | |||
"vendor/order!vendor/jquery-1.7", | |||
"vendor/order!vendor/underscore", | |||
"vendor/order!vendor/backbone", | |||
"vendor/order!../backbone.localStorage" | |||
], function() { | |||
return { _: _.noConflict(), Backbone: Backbone.noConflict() }; | |||
}); | |||
|
|||
define("underscore", ["backbone-loader"], function(Loader) { | |||
return Loader._; | |||
}); | |||
|
|||
define("backbone", ["backbone-loader"], function(Loader) { | |||
return Loader.Backbone; | |||
}); | |||
|
|||
require(["backbone"], function(Backbone) { | |||
var Library = Backbone.Collection.extend({ | |||
localStorage: new Backbone.LocalStorage("libraryStore") | |||
}); | |||
|
|||
var attrs = { | |||
title : 'The Tempest', | |||
author : 'Bill Shakespeare', | |||
length : 123 | |||
}; | |||
|
|||
var library = null; | |||
|
|||
module("localStorage on collections", { | |||
setup: function() { | |||
window.localStorage.clear(); | |||
library = new Library(); | |||
} | |||
}); | |||
|
|||
test("should be empty initially", function() { | |||
equals(library.length, 0, 'empty initially'); | |||
library.fetch(); | |||
equals(library.length, 0, 'empty read'); | |||
}); | |||
|
|||
test("should create item", function() { | |||
library.create(attrs); | |||
equals(library.length, 1, 'one item added'); | |||
equals(library.first().get('title'), 'The Tempest', 'title was read'); | |||
equals(library.first().get('author'), 'Bill Shakespeare', 'author was read'); | |||
equals(library.first().get('length'), 123, 'length was read'); | |||
}); | |||
|
|||
test("should discard unsaved changes on fetch", function() { | |||
library.create(attrs); | |||
library.first().set({ 'title': "Wombat's Fun Adventure" }); | |||
equals(library.first().get('title'), "Wombat's Fun Adventure", 'title changed, but not saved'); | |||
library.fetch(); | |||
equals(library.first().get('title'), 'The Tempest', 'title was read'); | |||
}); | |||
|
|||
test("should persist changes", function(){ | |||
library.create(attrs); | |||
equals(library.first().get('author'), 'Bill Shakespeare', 'author was read'); | |||
library.first().save({ author: 'William Shakespeare' }); | |||
library.fetch(); | |||
equals(library.first().get('author'), 'William Shakespeare', 'verify author update'); | |||
}); | |||
}); | |||
|
Oops, something went wrong.