/
todos.js
69 lines (47 loc) · 1.57 KB
/
todos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
define(
[
'require',
'when',
'wire',
'collections/todos'
],
function( require, when, wire, Todos ) {
console.log( wire );
var Backbone = require( 'backbone' );
describe( "Todos collection", function() {
it( "is a backbone collection", function() {
// It returned something
expect( Todos ).toBeDefined();
// Check for a function that only a backbone collection is likely to have
expect( ( new Todos() ).getByCid ).toBeDefined();
} );
it( "create a new context, containing a new todo view and model", function() {
// This is a little hard to test without testing the todo spec
// BEWARE: Wire does a lot of magic here!
var todos = new Todos(),
deferred = when.defer(),
model = { test: 'model' },
add_stub = sinon.stub( todos, 'add' );
todos._createTodo = function() { return deferred; };
todos.create( {} );
deferred.resolve( {
view: {},
model: model
} );
// Check that the model is added to the collection
expect( add_stub ).toHaveBeenCalledOnce();
expect( add_stub ).toHaveBeenCalledWith( model );
} );
it( "check for models that are done or remaining", function() {
var todos = new Todos(
[
new Backbone.Model( { done: true } ),
new Backbone.Model( { done: true } ),
new Backbone.Model( { done: false } )
]
);
expect( todos.done().length ).toEqual( 2 );
expect( todos.remaining().length ).toEqual( 1 );
} );
} );
} );