Skip to content

Commit

Permalink
Added toJSON to observable and tests for it.
Browse files Browse the repository at this point in the history
Closes #86.
  • Loading branch information
Joscha Rohmann committed Oct 25, 2015
1 parent c552b7d commit d34d60d
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 d34d60d

Please sign in to comment.