Skip to content

Commit

Permalink
Failing tests for using .toJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodgkins committed Oct 16, 2018
1 parent e4151e7 commit 7f6c2d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
36 changes: 35 additions & 1 deletion test/spec/lib/database/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,41 @@ describe('store', function() {
});
});

[new Date(), /foo/].forEach(function(v) {
it('should let .toJSON() be used as value', function() {
class Something {
constructor() {
Object.defineProperty(this, 'key', {value: 'definedValue', enumberable: false});
Object.defineProperty(this, 'key2', {value: 'definedValue'});
}
toJSON() {
return {key: 'val'};
}
}

expect(store.create(new Something()).$value()).to.eql({key: 'val'});
expect(store.create({v: new Something()}).$value()).to.eql({v: {key: 'val'}});
});

it('should not let classes without .toJSON() be used as value', function() {
class Something {
constructor() {
Object.defineProperty(this, 'key', {value: 'definedValue', enumberable: false});
Object.defineProperty(this, 'key2', {value: 'definedValue'});
}
}

expect(() => store.create(new Something())).to.throw();
expect(() => store.create({v: new Something()})).to.throw();
});

[new Date()].forEach(function(v) {
it(`should let ${v.constructor.name} be used as value`, function() {
expect(store.create(v).$value()).to.eql(v.toJSON());
expect(store.create({v}).$value()).to.eql({v: v.toJSON()});
});
});

[/foo/].forEach(function(v) {
it(`should not let ${v.constructor.name} be used as value`, function() {
expect(() => store.create(v)).to.throw();
expect(() => store.create({v})).to.throw();
Expand Down
8 changes: 7 additions & 1 deletion test/spec/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ describe('util', function() {

describe('setFirebaseData', function() {

it('should throw on invalid data', function() {
it('should not throw on invalid data', function() {
expect(
() => util.setFirebaseData(new Date())
).to.not.throw();
});

it('should throw on invalid data', function() {
expect(
() => util.setFirebaseData(/regex/)
).to.throw();
});

Expand Down

0 comments on commit 7f6c2d4

Please sign in to comment.