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

td.constructor() breaks instanceof #267

Closed
eric-parsons opened this issue Jun 22, 2017 · 3 comments
Closed

td.constructor() breaks instanceof #267

eric-parsons opened this issue Jun 22, 2017 · 3 comments

Comments

@eric-parsons
Copy link

It seems that starting with version 3.0 of testdouble.js, instanceof checks fail for instances of constructor doubles created via td.constructor():

class Dog { }
var FakeDog = td.constructor(Dog);
var dog = new FakeDog();

console.log(dog instanceof Dog); // true in 2.x, false in 3.x

The same is true for ES5-style constructors, i.e. function Dog() {}. This behaviour is in all 3.x versions up to and including 3.1.1. Unfortunately this is a pretty big breaking change for my code base, preventing me from being able to upgrade.

@searls
Copy link
Member

searls commented Jun 22, 2017

This was intentional because of bugs in how Babel handles type extension causing bugs. Additionally, extending actual types results in real constructors of faked dependencies being invoked, which was never intentional and definitely problematic.

You can get the old behacior by setting the extend constructor option to true:

https://github.com/testdouble/testdouble.js/blob/master/docs/C-configuration.md#tdconfig

@searls searls closed this as completed Jun 22, 2017
@searls
Copy link
Member

searls commented Jun 24, 2017

Your lucky day! By sheer coincidence, the work in #268 just happened to fix this constraint and enabled me to delete that option & restore 2.x's instanceof behavior. I wasn't aiming to fix this but it just happened to sort itself up.

Try 3.2.0 and re-test.

@eric-parsons
Copy link
Author

Just tried it with 3.2.0 -- works like a charm. Thanks!

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

2 participants