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

Test context is undefined #53

Open
henhal opened this issue Apr 17, 2020 · 0 comments
Open

Test context is undefined #53

henhal opened this issue Apr 17, 2020 · 0 comments

Comments

@henhal
Copy link

henhal commented Apr 17, 2020

I have a test suite in plain JS and a project which is only somewhat migrated to TS.
My tests works fine with regular mocha using the transpiled JS, but when using ts-mocha on the mixed js/ts code I get some difference in behaviour. Mainly, the context of the before/after functions is undefined.

Example:

before(async() => {
  // some setup code that uses the mocha test context through "this"
}

...
describe( ... )

When this is run with ts-mocha, this is undefined in before, after etc, with plain mocha this is set to the test context object.
Am I doing something wrong or does ts-mocha not have equivalent semantics as mocha?

EDIT: I found that arrow functions are discouraged in mocha: https://mochajs.org/#arrow-functions and that changing to function solves the issue! However, the same code works in mocha but not in ts-mocha, so there's still a discrepancy?

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

1 participant