From d34d60d84577f3eba3849b02a3fd964120afb48e Mon Sep 17 00:00:00 2001 From: Joscha Rohmann Date: Sun, 25 Oct 2015 02:58:59 +0200 Subject: [PATCH] Added toJSON to observable and tests for it. Closes #86. --- src/query/observable.js | 3 +++ test/spec/query/observables.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/query/observable.js b/src/query/observable.js index 68b638f..b0c24ff 100644 --- a/src/query/observable.js +++ b/src/query/observable.js @@ -312,6 +312,9 @@ define([ return value.toString(); } return String(value); + }, + toJSON: function() { + return this(); } }, diff --git a/test/spec/query/observables.js b/test/spec/query/observables.js index 8c4a0dc..5bae582 100644 --- a/test/spec/query/observables.js +++ b/test/spec/query/observables.js @@ -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))); + } + + }); })();