问题
is it possible with jest(jasmine) to ge the currently executed name of the test or describe inside the test?
Using Jasmine: How to get name of current test is not working anymore or at least with jest.
e.g.
test('Error missing body', (done) => {
console.log('Currently executing: ' + REFERENCE_TO_TEST_NAME);
done();
});
Thanks
回答1:
const testParam = 'any text you need';
describe(`${testParam}`, () => {
test('mind the backtick', () => {
console.log(`Currently executing: ${testParam}`);
});
});
回答2:
The tests are supposed to contain only the basic code for your test: Arrange / Act / Assert, so it's not a good practice to introduce this kind of code at this place. But if you want to log the currently running test, you can use the custom_reporter API: https://jasmine.github.io/2.1/custom_reporter.html
You can get the same result that you expect by adding this code:
jasmine.getEnv().addReporter({
specStarted: function(result) {
console.log(`Spec name: ${result.fullName}, description: ${result.description}`);
}
});
回答3:
you can try:
let spec = test('Error missing body', (done) => {
console.log('Currently executing: ' + spec.getFullName());
done();
});
来源:https://stackoverflow.com/questions/48168385/get-currently-executed-describe-test-name