-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change is only feature changes (and subtle fixes), to fully support a todomvc demo using bind.js
- Loading branch information
Showing
7 changed files
with
262 additions
and
30 deletions.
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
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/*global describe, assert, beforeEach: true, Bind, sinon, it*/ | ||
var sinon = require('sinon'); | ||
var assert = require('assert'); | ||
var bind = require('../'); | ||
|
||
describe('augmented array', function () { | ||
'use strict'; | ||
var data; | ||
var spy; | ||
|
||
beforeEach(function () { | ||
spy = sinon.spy(); | ||
|
||
data = bind({ | ||
list: [1,2,3] | ||
}, { | ||
list: spy, | ||
}); | ||
}); | ||
|
||
it('push', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
assert.ok(data.list.length === 3, 'length is right'); | ||
data.list.push(4); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 4, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 4, 'passed in was 4'); | ||
}); | ||
|
||
it('pop', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
data.list.pop(); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 2, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 2, 'new array accepted'); | ||
}); | ||
|
||
it('shift', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
var first = data.list.shift(); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 2, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 2, 'new array accepted'); | ||
assert.ok(first === 1, 'got first value'); | ||
}); | ||
|
||
it('unshift', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
data.list.unshift(0); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 4, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 4, 'new array accepted'); | ||
assert.ok(spy.args[cursor][0][0] === 0, 'got first value'); | ||
}); | ||
|
||
it('splice', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
data.list.splice(1, 1); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 2, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 2, 'new array accepted'); | ||
assert.ok(spy.args[cursor][0].toString() === '1,3', 'got first value'); | ||
}); | ||
}); | ||
|
||
|
||
describe('augmented array containing binds', function () { | ||
'use strict'; | ||
var data; | ||
var spy; | ||
|
||
beforeEach(function () { | ||
function makeBind(n) { | ||
return bind({ | ||
data: n, | ||
}, { | ||
data: function () {} | ||
}); | ||
} | ||
|
||
spy = sinon.spy(); | ||
|
||
data = bind({ | ||
list: [1,2,3].map(makeBind) | ||
}, { | ||
list: spy, | ||
}); | ||
}); | ||
|
||
it('shift', function () { | ||
var cursor = spy.args.length; | ||
var count = spy.callCount; | ||
data.list.shift(); | ||
assert.ok(spy.callCount === count + 1, 'call count increased'); | ||
assert.ok(data.list.length === 2, 'length is right'); | ||
assert.ok(spy.args[cursor][0].length === 2, 'new array accepted'); | ||
var values = data.list.map(function (v) { | ||
return v.data; | ||
}).join(','); | ||
console.log(values); | ||
assert.equal(values, '2,3', 'source data is correct'); | ||
}); | ||
}); |
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 | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ describe('checkboxes', function () { | |
|
||
|
||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.
1 comment
on commit 089ee6c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
Is this statement correct
value.toString === '[Object object]'
?
Seems like missed parentheses for method call.
@precious do you mean this line?