Skip to content

Commit

Permalink
Add tests with RequireJS and noConflict() versions of Underscore.js a…
Browse files Browse the repository at this point in the history
…nd Backbone.js
  • Loading branch information
juhovh committed May 8, 2012
1 parent 9e40540 commit f40becf
Show file tree
Hide file tree
Showing 6 changed files with 11,748 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
@@ -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
22 changes: 22 additions & 0 deletions tests/test2.html
@@ -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>
68 changes: 68 additions & 0 deletions tests/test2.js
@@ -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');
});
});

0 comments on commit f40becf

Please sign in to comment.