Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type check before value is changed
- Loading branch information
Showing
12 changed files
with
557 additions
and
237 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,87 @@ | ||
module.exports = function(config) { | ||
module.exports = function (config) { | ||
config.set({ | ||
frameworks: ['mocha', 'browserify', 'sinon', 'chai'], | ||
// base path, that will be used to resolve files and exclude | ||
basePath: '.', | ||
|
||
frameworks: ['mocha', 'browserify'], | ||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'*.js', | ||
'bind.js', | ||
'test/spec/*.js', | ||
'test/index.js', | ||
'lib/**/*.js', | ||
'test/**/*.html', | ||
'test/**/*.test.js', | ||
'test/**/*.browser.js', | ||
], | ||
|
||
client: { | ||
mocha: { | ||
reporter: 'html', // change Karma's debug.html to the mocha web reporter | ||
ui: 'tdd', | ||
}, | ||
preprocessors: { | ||
'test/**/*.html': ['html2js'], | ||
'lib/**/*.js': 'coverage', | ||
'lib/**/*.js': ['browserify'], | ||
'test/**/*.test.js': ['browserify'], | ||
'test/**/*.browser.js': ['browserify'], | ||
}, | ||
|
||
browserify: { | ||
debug: true, | ||
// transform: ['browserify-istanbul'], | ||
}, | ||
|
||
// use dots reporter, as travis terminal does not support escaping sequences | ||
// possible values: 'dots', 'progress' | ||
// CLI --reporters progress | ||
reporters: ['mocha', 'coverage'], | ||
coverageReporter: { | ||
type: 'lcov', | ||
dir: 'coverage' | ||
}, | ||
// web server port | ||
// CLI --port 9876 | ||
port: 9876, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
// CLI --colors --no-colors | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
// CLI --log-level debug | ||
logLevel: config.LOG_INFO, | ||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
// CLI --auto-watch --no-auto-watch | ||
autoWatch: true, | ||
|
||
// Start these browsers, currently available: | ||
// - Chrome | ||
// - ChromeCanary | ||
// - Firefox | ||
// - Opera | ||
// - Safari (only Mac) | ||
// - PhantomJS | ||
// - IE (only Windows) | ||
// CLI --browsers Chrome,Firefox,Safari | ||
browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], | ||
|
||
// If browser does not capture in given timeout [ms], kill it | ||
// CLI --capture-timeout 5000 | ||
captureTimeout: 20000, | ||
|
||
// Auto run tests on start (when browsers are captured) and exit | ||
// CLI --single-run --no-single-run | ||
singleRun: true, | ||
|
||
// report which specs are slower than 500ms | ||
// CLI --report-slower-than 500 | ||
reportSlowerThan: 500, | ||
|
||
plugins: [ | ||
'karma-mocha', | ||
'karma-mocha-reporter', | ||
'karma-coverage', | ||
'karma-chrome-launcher', | ||
'karma-firefox-launcher', | ||
'karma-html2js-preprocessor', | ||
'karma-browserify', | ||
], | ||
}); | ||
}; | ||
}; |
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,65 @@ | ||
/*globals describe:true, assert: true, beforeEach: true, Bind:true, sinon:true, it:true */ | ||
var sinon = require('sinon'); | ||
var assert = require('assert'); | ||
var Bind = require('../'); | ||
|
||
describe('numbers', function () { | ||
'use strict'; | ||
var data, spy, spy2, players; | ||
|
||
beforeEach(function () { | ||
spy = new sinon.spy(); | ||
spy2 = new sinon.spy(); | ||
players = new sinon.spy(); | ||
|
||
data = new Bind({ | ||
score: 10, | ||
players: [{ | ||
name: 'Remy', | ||
highscore: 300, | ||
}, { | ||
name: 'Julie', | ||
highscore: 350, | ||
},], | ||
}, { | ||
score: spy, | ||
'players.1.highscore': spy2, | ||
players: players, | ||
}); | ||
}); | ||
|
||
it('should allow raw value to change', function () { | ||
data.score = 11; | ||
assert(data.score === 11); | ||
data.score++; | ||
assert(data.score === 12); | ||
}); | ||
|
||
it('should trigger callback on change', function () { | ||
var callCount = spy.callCount; | ||
data.score = 11; | ||
assert(spy.callCount === (callCount + 1)); | ||
}); | ||
|
||
it('should trigger callback after init', function () { | ||
assert(spy.withArgs(10, undefined).calledOnce); | ||
}); | ||
|
||
it('should pass callback new value and old', function () { | ||
assert(spy.withArgs(10, undefined).calledOnce); | ||
|
||
data.score = 11; | ||
assert(spy.withArgs(11, 10).calledOnce); | ||
}); | ||
|
||
it('should trigger on deep object value change', function () { | ||
data.players[1].highscore++; | ||
assert(spy2.callCount === 2); | ||
}); | ||
|
||
it('should trigger on array item change', function () { | ||
var count = players.callCount; // because it's called on initial setup | ||
data.players.push({ name: 'Ellis', highscore: 50 }); | ||
assert(players.callCount === count + 1, 'new callcount: ' + players.callCount); | ||
}); | ||
}); |
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,29 @@ | ||
'use strict'; | ||
var sinon = require('sinon'); | ||
var assert = require('assert'); | ||
var Bind = require('../'); | ||
|
||
/*globals describe, assert, beforeEach, Bind, sinon, it */ | ||
describe('export', function () { | ||
var data; | ||
|
||
it('returns vanilla object', function () { | ||
var spy = sinon.spy(); | ||
var o = { | ||
name: 'remy', | ||
complex: { | ||
age: 20, | ||
location: 'house', | ||
}, | ||
}; | ||
var data = Bind(o, { | ||
name: spy, | ||
}); | ||
|
||
assert.ok(spy.calledWith('remy'), 'initial data set'); | ||
assert.ok(JSON.stringify(o) === JSON.stringify(data.__export()), | ||
'export returns same object'); | ||
}); | ||
|
||
|
||
}); |
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,33 @@ | ||
(function () { | ||
var ready = false; | ||
var sandbox = null; | ||
|
||
function setup() { | ||
destroy(); | ||
sandbox.style.visibilty = 'hidden'; | ||
sandbox.style.position = 'absolute'; | ||
sandbox.style.top = '-999999px'; | ||
sandbox.style.zIndex = '-1'; | ||
document.body.appendChild(sandbox); | ||
ready = true; | ||
} | ||
|
||
|
||
function insert(html) { | ||
setup(); | ||
sandbox.innerHTML = html; | ||
} | ||
|
||
function destroy() { | ||
if (sandbox) { | ||
sandbox.innerHTML = ''; | ||
sandbox.parentNode.removeChild(sandbox); | ||
} | ||
sandbox = document.createElement('div'); | ||
ready = false; | ||
}; | ||
|
||
if (typeof exports !== 'undefined') { | ||
module.exports = insert; | ||
} | ||
})(); |
Oops, something went wrong.