Problem with createStubInstance on a subclass with getter referencing property from superclass #1236

jasonzhu1991 opened this Issue Jan 8, 2017 · 2 comments


None yet

2 participants

  • Sinon version : 1.17.7
  • Environment : nodejs v7.3.0
  • Example:
const sinon = require('sinon');

class A {
  constructor() {
    this.a = { b: {} };

class B extends A {
  get c() {
    return this.a.b;

const stub = sinon.createStubInstance(B);

What did you expect to happen?
A stub should be returned

What actually happens
Error with stack trace:

TypeError: Cannot read property 'b' of undefined
at F.get c [as c] (repl:3:14)
at /node_modules/sinon/lib/sinon/walk.js:28:50
at Array.forEach (native)
at walkInternal (/node_modules/sinon/lib/sinon/walk.js:23:45)
at walkInternal (/tvbutler/node_modules/sinon/lib/sinon/walk.js:34:17)
at Object.walk (/node_modules/sinon/lib/sinon/walk.js:49:20)
at Object.stub (/node_modules/sinon/lib/sinon/stub.js:52:23)
at Object.sinon.createStubInstance (/node_modules/sinon/lib/sinon/util/core.js:383:26)
at repl:1:7
at realRunInThisContextScript (vm.js:22:35)

fatso83 commented Jan 8, 2017 edited

Can you please check if this works using Sinon 2 and report back? Just try npm install sinon@next. I hope this is fixed in master, but not sure. Anyway, we should probably still fix 1.17


@fatso83 Thanks for your reply! It works on 2.0.0-pre.5

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