Added a test

pull/2/head
Louis Chatriot 10 years ago
parent e2733f529e
commit 3b355a630d
  1. 3
      .gitignore
  2. 3
      lib/model.js
  3. 1
      test/model.test.js

3
.gitignore vendored

@ -17,3 +17,6 @@ node_modules
browser-version/src browser-version/src
browser-version/node_modules browser-version/node_modules
*.swp
*~

@ -72,8 +72,7 @@ function serialize (obj) {
if (v === null) { return null; } if (v === null) { return null; }
// Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit). // Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit).
// We can't use value directly because for dates it is already string in this function (date.toJSON was already called), // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), so we use this
// fortunately "this" is bound here to object which is owner of the key.
if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; } if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; }
return v; return v;

@ -82,6 +82,7 @@ describe('Model', function () {
b = model.serialize(a); b = model.serialize(a);
c = model.deserialize(b); c = model.deserialize(b);
b.indexOf('\n').should.equal(-1); b.indexOf('\n').should.equal(-1);
b.should.equal('{"test":{"$$date":' + d.getTime() + '}}');
util.isDate(c.test).should.equal(true); util.isDate(c.test).should.equal(true);
c.test.getTime().should.equal(d.getTime()); c.test.getTime().should.equal(d.getTime());
}); });

Loading…
Cancel
Save