I have created a method called testLoginFailed
let testloginFailed = (app, title, data) => {
it(title, function (done) {
request(app)
.post(apiEndPoints.auth.login)
.send(data)
.then((response) => {
response.statusCode.should.equal(401);
response.body.error.name.should.equal('Error');
response.body.error.message.should.equal('login failed');
response.body.error.code.should.equal('LOGIN_FAILED');
done();
})
.catch((error) => {
done(error);
});
});
};
and here is my describe block
describe('login negative Tests', () => {
before(function () {
let loginFailedTests = [
{
title: 'it should fail user login using mobile because of incorrect mobile',
data: {
username: '1223334444',
password: options.user.password
}
}, {
title: 'it should fail user login using mobile because of incorrect password',
data: {
username: options.user.mobileNumber,
password: options.user.password + '123'
}
}
];
});
loginFailedTests.forEach((test) => {
testloginFailed(app, test.title, test.data);
});
});
Problem Statment:
- I want to generate dynamic test cases using the function 'testloginFailed' described above.
- So I am calling the method in a loop with different test data set testloginFailed.
- The array testloginFailed is getting initialized in the before block as it needs some data which is in glocal scope using options.
Issue: When I am trying to use this array testloginFailed in step 2 above, it says
loginFailedTests.forEach((test) => { ^
ReferenceError: loginFailedTests is not defined