Sinon mock expects verify is setting my method to 'undefined' on restore (hasOwnProperty conflict) #1138

Open
launchcg-ztonia opened this Issue Sep 6, 2016 · 2 comments

Projects

None yet

1 participant

@launchcg-ztonia
launchcg-ztonia commented Sep 6, 2016 edited
  • Sinon version : please verify that the bug exists in the latest Sinon release
    sinon@1.17.5
  • Environment :
    node 4.5.0
    OSX El Capitain 10.11.5
  • Example URL :
  • Other libraries you are using:

"chai": "^3.4.0",
"mocha": "^2.3.3",
"mockery": "^1.4.1"

What did you expect to happen?
When my mocked object is 'verify'd, the original method must be restored.

What actually happens
The method is set as undefined

How to reproduce

Describe with code how to reproduce the faulty behaviour,
or link to code on JSBin or similar

var objectInstance = require('./MODULE');
var objectInstance2 = require('./MODULE2');
describe ("testincoming", function() {
  var mockObject, mockObject2;
  beforeEach(function() { mockObject = sinon.mock(objectInstance); })
  afterEach(function() { mockObject.restore() })

  describe("nested", function() {
  beforeEach(function() { mockObject2 = sinon.mock(objectInstance2); })
  afterEach(function() { mockObject2.restore() })
  it("test", function() {
    mockObject.expects('method').once().withArgs(5).returns(Promise.resolve());
    mockObject2.expects('method').once().withArgs(5).returns(Promise.resolve());
    return invokeSomethingElsePromise()
      .then(function() {
        mockObject2.verify(); // This is destroying my method
        mockObject.verify(); // This is not destroying my method. I can't tell what's different.
      });
  });
});
})

Please note, there are two nearly identical objects which I am mocking in this same way. Only ONE is exhibiting this behavior and the other is not. I cannot paste source code, but I can answer follow up questions.

@launchcg-ztonia

I have found the source of the error.
The mocked method has implemented the method 'hasOwnProperty'
Which is conflicting in sinon/util/core and causing the restore method to fail.

@launchcg-ztonia launchcg-ztonia changed the title from Sinon mock expects verify is setting my method to 'undefined' on restore. to Sinon mock expects verify is setting my method to 'undefined' on restore (hasOwnProperty conflict) Sep 6, 2016
@launchcg-ztonia

I now see related issue
#887
But it is marked closed resolved.

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