Automattic / Automattic/expect.js
expect(fn).to.throwError() steals context
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 207
- PR merge metrics
- No merged PRs in 30d
Description
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
``` coffeescript
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue identifies expect(fn).to.throwError() as the entry point and links a gist demonstrating the context difference. Read its implementation along with nearby documentation and tests, reproduce the example, and determine whether documenting the closure workaround resolves the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100