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

expect(fn).to.throwError() steals context #106

Open
stephenprater opened this issue Apr 14, 2014 · 5 comments
Open

expect(fn).to.throwError() steals context #106

stephenprater opened this issue Apr 14, 2014 · 5 comments

Comments

@stephenprater
Copy link

https://gist.github.com/stephenprater/10659056

I would expect this to work - but j.toJSON is executed in the context of expect, and not in j - the work around is

expect( -> j.toJSON() ).to.throwError()

That's pretty unintuitive and not really hinted at by the docs. Although it's probably not possible to know what binding to execute the function in - maybe the docs should indicate you should pass a closure to prevent this.

@shime
Copy link

shime commented Sep 9, 2014

👍

@janmarek
Copy link
Contributor

janmarek commented Nov 2, 2014

This is javascript. You can NEVER pass object.method somewhere and expect it will be called with object as "this" argument.

@shime
Copy link

shime commented Nov 2, 2014

@janmarek check this out

@janmarek
Copy link
Contributor

janmarek commented Nov 2, 2014

@shime How is it relevant?

Imagine the expect function receiving a parameter. How would you know inside the function if user passed function () { ... } or object.method or object.getSomething().getSomethingElse().method? Without this information you don't know what object can be set as "this" argument of call or apply.

@stephenprater
Copy link
Author

I'm not arguing with the implementation - I get why it's like that - it's that the documentation doesn't really provide an example of this assertion being used the way you're likely to want to use it - and the behavior of javascript in this instance isn't super-obvious. I'm pretty sure I made this error report in frustration after beating my head against it for a while, and thought some body else might benefit from my suffering.

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

3 participants