From aad21e916cc55965a80a9543b5d6a22d7d520274 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Tue, 19 Mar 2013 14:05:38 +0400 Subject: [PATCH] Added json test --- test/json.test.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/json.test.js diff --git a/test/json.test.js b/test/json.test.js new file mode 100644 index 00000000..b2163224 --- /dev/null +++ b/test/json.test.js @@ -0,0 +1,36 @@ +var Schema = require('jugglingdb').Schema; +var should = require('should'); + +describe('JSON property', function() { + var schema, Model; + + it('could be defined', function() { + schema = new Schema('memory'); + Model = schema.define('Model', {propertyName: Schema.JSON}); + var m = new Model; + m.should.have.property('propertyName'); + should.not.exist(m.propertyName); + }); + + it('should accept JSON in constructor and return object', function() { + var m = new Model({ + propertyName: '{"foo": "bar"}' + }); + m.propertyName.should.be.an.Object; + m.propertyName.foo.should.equal('bar'); + }); + + it('should accept object in setter and return object', function() { + var m = new Model; + m.propertyName = {"foo": "bar"}; + m.propertyName.should.be.an.Object; + m.propertyName.foo.should.equal('bar'); + }); + + it('should accept string in setter and return string', function() { + var m = new Model; + m.propertyName = '{"foo": "bar"}'; + m.propertyName.should.be.a.String; + m.propertyName.should.equal('{"foo": "bar"}'); + }); +});