Javascript概念可运行所有测试用例

时间:2018-08-24 07:52:35

标签: javascript arrays object login testcase

我正在尝试运行所有可能的测试用例,以使loginValidation函数包含在我的项目中。

这是LoginValidation登录

let checkLogin = (email, password, allUsers) => {
let isUserFound = false;
let passwordCorrect = false;
for (currentUser in allUsers){
console.log(currentUser);

  if(allUsers[currentUser]['email'] === email){

      if(allUsers[currentUser]['password'] === password){
           isUserFound= true;
           passwordCorrect=true;
           break;
      }else{
           isUserFound= true;
           passwordCorrect=false; break;
      }

 }else{
       isUserFound = false;
  }

}//loop ends

 if(isUserFound === true && passwordCorrect === true){
       console.log('You are logged in');
 }else if(isUserFound  === true && passwordCorrect === false){
       console.log('You have provided incorrect password');
 }else{
     console.log('No user with this email found');
  }
};

运行代码

checkLogin('emailid1@email.com','password1',allUsers);

现在我的问题是可以在许多方面定义 allUsers

我对 allUsers 的解决方案。

  let allUsers = {
         '1':{'email':'emailid1@email.com','password':'password1'},
         '2':{'email':'emailid2@email.com','password':'password2'},
         '3':{'email':'emailid3@email.com','password':'password3'},
         '4':{'email':'emailid4@email.com','password':'password4'}
      };

将所有用户视为对象。如果某人具有 allUsers数组,并且他们尝试通过

调用该函数怎么办?
 checkLogin('emailid1@email.com','password1', ...allUsers); 

应如何定义 allUsers 以使其在所有用例中都可以通过。

0 个答案:

没有答案