Skip to content

Instantly share code, notes, and snippets.

@bobzoller
Created September 27, 2012 00:27
Show Gist options
  • Select an option

  • Save bobzoller/3791467 to your computer and use it in GitHub Desktop.

Select an option

Save bobzoller/3791467 to your computer and use it in GitHub Desktop.
mongoose set nested bug?
mongoose = require 'mongoose'
schema = new mongoose.Schema
nested:
thing: String
Bob = mongoose.model('Bob', schema)
describe 'Bob', ->
bob = null
beforeEach ->
bob = new Bob(nested: {thing: 'widget'})
expect(bob.nested.thing).toEqual 'widget'
it 'set null', ->
bob.set(nested: null)
expect(bob.get('nested.thing')).toBeUndefined()
it 'set undefined', ->
bob.set(nested: undefined)
expect(bob.get('nested.thing')).toBeUndefined()
it 'set empty object', ->
bob.set(nested: {})
expect(bob.get('nested.thing')).toBeUndefined()
it 'virtual property null', ->
bob.nested = null
expect(bob.get('nested.thing')).toBeUndefined()
it 'virtual property undefined', ->
bob.nested = undefined
expect(bob.get('nested.thing')).toBeUndefined()
it 'virtual property empty object', ->
bob.nested = {}
expect(bob.get('nested.thing')).toBeUndefined()
@bobzoller

Copy link
Copy Markdown
Author

run with jasmine-node --coffee bob.spec.coffee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment