Skip to content

Commit

Permalink
Merge pull request #107 from Kanaye/observable-to-json
Browse files Browse the repository at this point in the history
Added toJSON to observable and tests for it.
  • Loading branch information
astoilkov committed Oct 26, 2015
2 parents c552b7d + d34d60d commit 743bea5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/query/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ define([
return value.toString();
}
return String(value);
},
toJSON: function() {
return this();
}
},

Expand Down
17 changes: 17 additions & 0 deletions test/spec/query/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,21 @@
expect(observable.update).toHaveBeenCalled();
});
});

it('can be JSON.stringified', function () {

var values = [42, 'some string', [1,2,3], {
a:'some string',
b: 42,
c: [1,2,34],
d: {a: 'hello'},
e: blocks.observable('that works ?')
}];

for (var i = 0; i < values.length; i++) {
var value = values[i];
expect(JSON.stringify(value)).toBe(JSON.stringify(blocks.observable(value)));
}

});
})();

0 comments on commit 743bea5

Please sign in to comment.