This code works: I used the variable testTitle in beforeEach function.
const list = [
{ title: 'login', uri: '/login', should: 'Login' },
{ title: 'signup', uri: '/signup', should: 'Create'}
];
let testTitle = '';
beforeEach(function() {
testTitle = this.currentTest.fullTitle();
});
describe('navegation', () => {
list.forEach(function(item) {
it(item.title, (done, obj) => {
// ------------------------------------
// Not work it
// console.log(this.test.fullTitle());
// ------------------------------------
request(server)
.get(item.uri)
.expect(constant.STATUS.OK)
.then(res => {
res.text.should.include(item.should);
done();
})
.catch(err => {
console.log(testTitle + ': ' + err);
return done(err);
});
});
});
});
Question:
How I can improve my code for used this.test.fullTitle() directly on loop and avoid I used the variable testTitle and beforeEach function?
Thanks.
Your it has to use function instead of => to get access to Mocha's this object; this.test.fullTitle() should work with function.
Thanks @ScottFreeCode!
Most helpful comment
Your
ithas to usefunctioninstead of=>to get access to Mocha'sthisobject;this.test.fullTitle()should work withfunction.