-
Notifications
You must be signed in to change notification settings - Fork 142
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
Figure out babel+instanceof+constructor problems with class extension #241
Comments
Not sure if this is the same bug, but in |
I don't know what the cause here is, but could you try pulling down testdouble.js, link this example to the lib and then git bisect it to find the offending hash? (Btw, @razor-x, this is almost certainly unrelated) |
Ok, somewhat frustratingly this fix doesn't work in babel |
❤️ git bisect works: c54b741
|
I'm sorry for the delay in getting back to you. This is pretty confusing so strap in. My preliminary conclusion after looking at this more closely is that you were, in a sense, using our ES Proxy support in an ambiguous way that we didn't intend to actually support. If you look at this line of your demo project, you stub To illustrate, in your "working" example, I could get away with this: const assert = require('assert')
const td = require('testdouble')
class Foo {
bar () {
return false
}
}
const doBar = foo => foo.lololol()
const foo = td.object(new Foo())
td.when(foo.lololol()).thenReturn(true)
assert.ok(doBar(foo)) This is clearly not what you'd expect, because you're handing Instead, what I'd typically recommend is that you As a result of the above I'm closing this issue, but am open to hearing your reaction |
Thanks for the response. As I didn't get any feedback before I submitted the PR assuming a regression. The Something like this makes sense to me and would require minimal refactoring to change: const assert = require('assert')
const td = require('testdouble')
class Foo {
bar () {
return false
}
}
const doBar = foo => foo.bar()
const foo = new td.constructor(Foo)
td.when(foo.bar()).thenReturn(true)
assert.ok(doBar(foo)) but it fails with
Also, trying to mimic the example in the docs const assert = require('assert')
const td = require('testdouble')
class Foo {
bar () {
return false
}
}
const doBar = foo => foo.bar()
const FakeFoo = td.constructor(Foo)
td.when(FakeFoo.prototype.bar()).thenReturn(true)
assert.ok(doBar(new FakeFoo())) fails with
|
Yes, the last failure is the issue that I thought this issue was all about to begin with and needs to be addressed with some kind of solution like #242 |
For the meantime, you can just change your test to |
Resolved by #254 and landed in testdouble@3.0 |
Moving #157 here now that we know what's going on.
Three things at once going on here: when you replace a class, td.js will extend that class and give you a fake one.
instanceof
checks in the subject. This was raised by several issues in td 1.x and was the main motivation for the changesuper
, which sucks because a fake thing shouldn't be invoking a real constructornew
keyword, which raises an error under v8 versions that support theclass
keywordDupes: #240
The text was updated successfully, but these errors were encountered: