README
What is this?
This is a very hacky solution to this issue on Jasmine's GitHub.
Jasmine's devs did a tremendous job making it difficult to get any information about the current test execution environment. In my opinion, this is a design flaw.
Please use it with care and good intentions.
How does it work?
it
is overriden like in Pyrolistical's comment- spec's description getter is overriden to assign the spec to an outside scope
- when getCurrentSpec is called from within a test case, we try running it of the current's environment
- this throws an error because we are already in a test case
- spec's description is used to build the error message - our overridden getter is called
- finally, current spec is returned from the outside context
How do I use it?
Unit testing
First, add the project as a test dependency in package.json
file:
"devDependencies": {
"smack-my-jasmine-up": "^0.0.5"
...
}
Next, import JasmineSmacker
in your test file (or any class that runs within a test):
const JasmineSmacker = require('smack-my-jasmine-up');
Finally, fetch the test case's name and use it for whatever reason:
const currentTestName = JasmineSmacker.getCurrentTestName();
if (currentTestName !== undefined) {
console.log(`cool, we are within ${currentTestName}!`)
}
Contribution guidelines
All I ask for is tests and documentation in form of JS docstrings. Feel free to submit a PR if you feel like it.