Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #141 from Tavriets/master

Tests and fix for issue #137.
  • Loading branch information...
commit 48a4b646c0d5a18c6d573888ef16cd6ba784c815 2 parents 3f7a34c + 2e9918d
Roy Jacobs RoyJacobs authored
Showing with 29 additions and 1 deletion.
  1. +1 −1  knockout.mapping.js
  2. +28 −0 spec/mappingBehaviors.js
2  knockout.mapping.js
View
@@ -470,7 +470,7 @@
if(options.observe.length > 0 && ko.utils.arrayIndexOf(options.observe, fullPropertyName) == -1)
{
- mappedRootObject[indexer] = value();
+ mappedRootObject[indexer] = ko.utils.unwrapObservable(value);
options.copiedProperties[fullPropertyName] = true;
return;
}
28 spec/mappingBehaviors.js
View
@@ -1778,6 +1778,34 @@ test('ko.mapping.fromJS should copy specified single property, also when going b
equal(js.b, undefined);
});
+test('ko.mapping.fromJS with observe option should not fail when map data with sub-object', function() {
+ var data = {
+ a: "a",
+ b: {
+ c: "c"
+ }
+ };
+
+ var result = ko.mapping.fromJS(data, { observe: "a" });
+ equal(ko.isObservable(result.a), true);
+ equal(ko.isObservable(result.b), false);
+ equal(ko.isObservable(result.b.c), false);
+});
+
+test('ko.mapping.fromJS should observe property in sub-object', function() {
+ var data = {
+ a: "a",
+ b: {
+ c: "c"
+ }
+ };
+
+ var result = ko.mapping.fromJS(data, { observe: "b.c" });
+ equal(ko.isObservable(result.a), false);
+ equal(ko.isObservable(result.b), false);
+ equal(ko.isObservable(result.b.c), true);
+});
+
test('ko.mapping.fromJS explicit declared none observable members should not be mapped to an observable', function() {
var data = {
a: "a",
Please sign in to comment.
Something went wrong with that request. Please try again.