Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property getter broken in 1.17.0 #847

Closed
MaerF0x0 opened this issue Sep 23, 2015 · 4 comments
Closed

property getter broken in 1.17.0 #847

MaerF0x0 opened this issue Sep 23, 2015 · 4 comments

Comments

@MaerF0x0
Copy link

The following code works in 1.16.1 but fails in 1.17.0
(with mocha and mongodb)

sinon = require 'sinon'
assert = require 'assert'

describe "mock collection", ->
   beforeEach ->
     @collection = sinon.createStubInstance(Collection)
     sinon.stub @collection, 'collectionName', get: -> 'users'

   it 'should return users', ->
     assert.equal @collection.collectionName , 'users'

Will throw this err:

1) permissions: scoped_query "before each" hook:
     TypeError: Cannot read property 'name' of undefined
    at [object Object].Object.defineProperty.get [as collectionName] (/Users/user/code/api/node_modules/mongodb/lib/collection.js:130:52)
    at /Users/user/code/api/node_modules/sinon/lib/sinon/walk.js:34:43
    at Array.forEach (native)
    at walk (/Users/user/code/api/node_modules/sinon/lib/sinon/walk.js:33:45)
    at Object.walk (/Users/user/code/api/node_modules/sinon/lib/sinon/walk.js:39:17)
    at Object.stub (/Users/user/code/api/node_modules/sinon/lib/sinon/stub.js:52:23)
    at Object.sinon.createStubInstance (/Users/user/code/api/node_modules/sinon/lib/sinon/util/core.js:361:26)
    at Context.<anonymous> (/Users/user/code/api/test/permissions.coffee:277:7)
    at Hook.Runnable.run (/Users/user/code/api/node_modules/mocha/lib/runnable.js:200:32)
    at next (/Users/user/code/api/node_modules/mocha/lib/runner.js:201:10)
    at /Users/user/code/api/node_modules/mocha/lib/runner.js:212:5
    at process._tickDomainCallback (node.js:492:13)

For reference that line looks like:

Object.defineProperty(Collection.prototype, 'collectionName', {
  enumerable: true, get: function() { return this.s.name; }
});
@mrjackdavis
Copy link

I'm having a similar problem, where createStubInstance is throwing an error.

var sequelize = sinon.createStubInstance(Sequelize);

results in:

TypeError: Cannot read property 'getConnectorManager' of undefined
  at Object.defineProperty.get (node_modules/sequelize/lib/sequelize.js:279:35)
  at node_modules/sinon/lib/sinon/walk.js:34:43
  at Array.forEach (native)
  at walk (node_modules/sinon/lib/sinon/walk.js:33:45)
  at Object.walk (node_modules/sinon/lib/sinon/walk.js:39:17)
  at Object.stub (node_modules/sinon/lib/sinon/stub.js:52:23)
  at Object.sinon.createStubInstance (node_modules/sinon/lib/sinon/util/core.js:361:26)
  at Context.<anonymous> (tests/unit/_ContactStoreTests.js:16:26)

Works in version 1.16.x but fails in 1.17.0

@fatso83
Copy link
Contributor

fatso83 commented Sep 25, 2015

Seems like the regression was introduced by 079b00f which was a fix for #777
@traviskaufman : any idea what is happening?

@traviskaufman
Copy link
Contributor

I believe this has to do with walk not handling getters properly. Looking into it now.

@traviskaufman
Copy link
Contributor

Yeah this was happening because walk was not invoking accessors defined on prototype objects on the original receiving objects, therefore trying to dereference a non-existent property. Submitted #857 a fix.

mroderick added a commit that referenced this issue Sep 26, 2015
Fix #847: Ensure walk invokes accessors directly on target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants