Skip to content

Conversation

@alex94cp
Copy link
Contributor

@alex94cp alex94cp commented Aug 25, 2017

Background

Though it is easy to replicate this functionality (eg: sinon.match(x => s instanceof foo)), the fact that this is not supported out-of-the-box can produce confusion, as the behaviour of instanceOf matchers and the instanceof operator differs regarding [Symbol.hasInstance].

Solution

This PR addresses this issue by lifting the limitation to allow not only functions, but any object with [Symbol.hasInstance] method, as defined by the standard, if supported by the interpreter.

How to verify

  1. Check out this branch
  2. npm install
  3. node (make sure your node version supports ES6 symbols)
  4. var sinon = require("./")
  5. var matcher = sinon.match.instanceOf({ [Symbol.hasInstance]: () => true })
  6. matcher.test("foo") // returns true

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

@fatso83 fatso83 merged commit 15d5737 into sinonjs:master Aug 27, 2017
@fatso83
Copy link
Contributor

fatso83 commented Aug 27, 2017

Thank you!

@mroderick mroderick added the semver:minor changes will cause a new minor version label Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:minor changes will cause a new minor version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants