Do you want to request a feature or report a bug?
Question/Feature
What is the current behavior?
I have a test suite that was working fine with Jest 18.0. When I upgraded to Jest 18.1, many of my tests started failing with the message, "ReferenceError: context is not defined".
It appears that context was removed as a synonym of describe in #2384, but no reasoning was given there, other than that it was "unused".
It seems like such a breaking change should not have been introduced in a point release.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
What is the expected behavior?
My understanding was that context was provided as an alias for describe to make it easier to port tests from other frameworks to Jest. Certainly, this is the case for us, as we've been migrating several projects from Mocha to Jest recently.
In many situations, I find context to communicate my intentions better than describe, so I really like having the alias.
I would like to see the context alias restored and documented as part of Jest's API. To me, it is similar to having it and test as aliases of each other.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest 18.1.0
Yarn 0.18.1
Node 6.9.2
OS/X 10.11.6
Context was controversial when it was added in #1632. We are currently rewriting the documentation of Jest and were analyzing the globals we add and realized context was almost entirely unused so we decided to remove this alias again. If you'd like to bring it back, you can do global.context = describe in a setupTestFrameworkScriptFile setting.
As to why this happened in a minor, here is what happened:
@cpojer Thanks for the response. First, let me apologize for the tone of my original issue. I didn't spend enough time on it, and it came across sounding much harsher than I intended. I'm also sorry that you had to give up some vacation time to deal with an issue caused by someone else's change. I really appreciate the work you all have done on this project. It's because of that work that I'm even looking at Jest as an option.
I had thought about the global.context = describe solution, but I've already run across two tools this week that don't support context: globals and eslint-plugin-jest. That's why I was hoping for context to become a documented feature.
That said, I understand your reasoning for dropping it, though I disagree. And I understand the unfortunate circumstances that resulted in that happening on a point release. I'm not a big fan of multiple release tracks, so I wouldn't suggest you make your process more complicated than it is.
Again, thanks everyone for your work on the project!
Thanks for your response. ❤️
@cpojer re: global.context = describe to bring context back...
I've done this in several node projects, however, for the life of me I can't get it to work with vscode in a project where the test files are typescript (using ts-jest). The tests run fine if I add a declaration file and wire it up properly for use in tsconfig's types and typeRoots properties, but vscode's intellisense underlines the instances of context with a ts2304 error.
The only way I've been able to get this to go away is to create a ts file (which _must_ be open in the editor at all times) that is added to setupFilesAfterEnv with a /// <reference path="path/to/my/index.d.ts" /> (index.d.ts is where I declare var context: jest.Describe). The moment I close the file with the /// reference, vscode can't find the name "context" anymore.
Thanks in advance.
Most helpful comment
@cpojer Thanks for the response. First, let me apologize for the tone of my original issue. I didn't spend enough time on it, and it came across sounding much harsher than I intended. I'm also sorry that you had to give up some vacation time to deal with an issue caused by someone else's change. I really appreciate the work you all have done on this project. It's because of that work that I'm even looking at Jest as an option.
I had thought about the
global.context = describesolution, but I've already run across two tools this week that don't support context: globals and eslint-plugin-jest. That's why I was hoping for context to become a documented feature.That said, I understand your reasoning for dropping it, though I disagree. And I understand the unfortunate circumstances that resulted in that happening on a point release. I'm not a big fan of multiple release tracks, so I wouldn't suggest you make your process more complicated than it is.
Again, thanks everyone for your work on the project!