forked from knockout/knockout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
193 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
})(window,document,navigator,window["jQuery"]); | ||
}()); |
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 +1,6 @@ | ||
(function(window,document,navigator,jQuery,undefined){ | ||
(function(undefined){ | ||
var window = this || (0,eval)('this'), // Use global 'this' | ||
document = window['document'], | ||
navigator = window['navigator'], | ||
jQuery = window["jQuery"], | ||
JSON = window["JSON"]; |
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,75 @@ | ||
|
||
describe('Compare Arrays', function() { | ||
it('Should recognize when two arrays have the same contents', function () { | ||
var subject = ["A", {}, function () { } ]; | ||
var compareResult = ko.utils.compareArrays(subject, subject.slice(0)); | ||
|
||
expect(compareResult.length).toEqual(subject.length); | ||
for (var i = 0; i < subject.length; i++) { | ||
expect(compareResult[i].status).toEqual("retained"); | ||
expect(compareResult[i].value).toEqual(subject[i]); | ||
} | ||
}); | ||
|
||
it('Should recognize added items', function () { | ||
var oldArray = ["A", "B"]; | ||
var newArray = ["A", "A2", "A3", "B", "B2"]; | ||
var compareResult = ko.utils.compareArrays(oldArray, newArray); | ||
expect(compareResult).toEqual([ | ||
{ status: "retained", value: "A" }, | ||
{ status: "added", value: "A2", index: 1 }, | ||
{ status: "added", value: "A3", index: 2 }, | ||
{ status: "retained", value: "B" }, | ||
{ status: "added", value: "B2", index: 4 } | ||
]); | ||
}); | ||
|
||
it('Should recognize deleted items', function () { | ||
var oldArray = ["A", "B", "C", "D", "E"]; | ||
var newArray = ["B", "C", "E"]; | ||
var compareResult = ko.utils.compareArrays(oldArray, newArray); | ||
expect(compareResult).toEqual([ | ||
{ status: "deleted", value: "A", index: 0 }, | ||
{ status: "retained", value: "B" }, | ||
{ status: "retained", value: "C" }, | ||
{ status: "deleted", value: "D", index: 3 }, | ||
{ status: "retained", value: "E" } | ||
]); | ||
}); | ||
|
||
it('Should recognize mixed edits', function () { | ||
var oldArray = ["A", "B", "C", "D", "E"]; | ||
var newArray = [123, "A", "E", "C", "D"]; | ||
var compareResult = ko.utils.compareArrays(oldArray, newArray); | ||
expect(compareResult).toEqual([ | ||
{ status: "added", value: 123, index: 0 }, | ||
{ status: "retained", value: "A" }, | ||
{ status: "deleted", value: "B", index: 1 }, | ||
{ status: "added", value: "E", index: 2, moved: 4 }, | ||
{ status: "retained", value: "C" }, | ||
{ status: "retained", value: "D" }, | ||
{ status: "deleted", value: "E", index: 4, moved: 2 } | ||
]); | ||
}); | ||
|
||
it('Should recognize replaced array', function () { | ||
var oldArray = ["A", "B", "C", "D", "E"]; | ||
var newArray = ["F", "G", "H", "I", "J"]; | ||
var compareResult = ko.utils.compareArrays(oldArray, newArray); | ||
// The order of added and deleted doesn't really matter. We sort by a property that | ||
// contains unique values to ensure the results are in a known order for verification. | ||
compareResult.sort(function(a, b) { return a.value.localeCompare(b.value) }); | ||
expect(compareResult).toEqual([ | ||
{ status: "deleted", value: "A", index: 0}, | ||
{ status: "deleted", value: "B", index: 1}, | ||
{ status: "deleted", value: "C", index: 2}, | ||
{ status: "deleted", value: "D", index: 3}, | ||
{ status: "deleted", value: "E", index: 4}, | ||
{ status: "added", value: "F", index: 0}, | ||
{ status: "added", value: "G", index: 1}, | ||
{ status: "added", value: "H", index: 2}, | ||
{ status: "added", value: "I", index: 3}, | ||
{ status: "added", value: "J", index: 4} | ||
]); | ||
}); | ||
}); |
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,21 @@ | ||
|
||
describe('Dependent Observable DOM', function() { | ||
it('Should register DOM node disposal callback only if active after the initial evaluation', function() { | ||
// Set up an active one | ||
var nodeForActive = document.createElement('DIV'), | ||
observable = ko.observable('initial'), | ||
activeDependentObservable = ko.dependentObservable({ read: function() { return observable(); }, disposeWhenNodeIsRemoved: nodeForActive }); | ||
var nodeForInactive = document.createElement('DIV') | ||
inactiveDependentObservable = ko.dependentObservable({ read: function() { return 123; }, disposeWhenNodeIsRemoved: nodeForInactive }); | ||
|
||
expect(activeDependentObservable.isActive()).toEqual(true); | ||
expect(inactiveDependentObservable.isActive()).toEqual(false); | ||
|
||
// Infer existence of disposal callbacks from presence/absence of DOM data. This is really just an implementation detail, | ||
// and so it's unusual to rely on it in a spec. However, the presence/absence of the callback isn't exposed in any other way, | ||
// and if the implementation ever changes, this spec should automatically fail because we're checking for both the positive | ||
// and negative cases. | ||
expect(ko.utils.domData.clear(nodeForActive)).toEqual(true); // There was a callback | ||
expect(ko.utils.domData.clear(nodeForInactive)).toEqual(false); // There was no callback | ||
}); | ||
}) |
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,72 @@ | ||
console.log("Running Knockout tests in Node.js"); | ||
|
||
var fs = require('fs'); | ||
var jasmine = require('./lib/jasmine-1.2.0/jasmine'); | ||
|
||
// export jasmine globals | ||
for (var key in jasmine) { | ||
global[key] = jasmine[key]; | ||
} | ||
|
||
// add our jasmine extensions to the exported globals | ||
require('./lib/jasmine.extensions'); | ||
|
||
// export ko globals | ||
if (process.argv.length > 2 && process.argv[2] == '--source') { | ||
// equivalent of ../build/knockout-raw.js | ||
global.DEBUG = true; | ||
global.ko = global.koExports = {}; | ||
global.knockoutDebugCallback = function(sources) { | ||
sources.unshift('build/fragments/extern-pre.js'); | ||
sources.push('build/fragments/extern-post.js'); | ||
eval(sources.reduce(function(all, source) { | ||
return all + '\n' + fs.readFileSync(source); | ||
}, '')); | ||
}; | ||
require('../build/fragments/source-references'); | ||
} else { | ||
global.ko = require('../build/output/knockout-latest.js'); | ||
} | ||
|
||
// reference behaviors that should work out of browser | ||
require('./arrayEditDetectionBehaviors'); | ||
require('./asyncBehaviors'); | ||
require('./dependentObservableBehaviors'); | ||
require('./expressionRewritingBehaviors'); | ||
require('./extenderBehaviors'); | ||
require('./mappingHelperBehaviors'); | ||
require('./observableArrayBehaviors'); | ||
require('./observableBehaviors'); | ||
require('./subscribableBehaviors'); | ||
|
||
// get reference to jasmine runtime | ||
var env = jasmine.jasmine.getEnv(); | ||
|
||
// create reporter to return results | ||
function failureFilter(item) { | ||
return !item.passed(); | ||
} | ||
env.addReporter({ | ||
reportRunnerResults:function (runner) { | ||
var results = runner.results(); | ||
runner.suites().map(function (suite) { | ||
// hack around suite results not having a description | ||
var suiteResults = suite.results(); | ||
suiteResults.description = suite.description; | ||
return suiteResults; | ||
}).filter(failureFilter).forEach(function (suite) { | ||
console.error(suite.description); | ||
suite.getItems().filter(failureFilter).forEach(function (spec) { | ||
console.error('\t' + spec.description); | ||
spec.getItems().filter(failureFilter).forEach(function (expectation) { | ||
console.error('\t\t' + expectation.message); | ||
}); | ||
}); | ||
}); | ||
console.log("Total:" + results.totalCount + " Passed:" + results.passedCount + " Failed:" + results.failedCount); | ||
process.exit(results.failedCount); | ||
} | ||
}); | ||
|
||
// good to go | ||
env.execute(); |
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
Oops, something went wrong.