我的代码中有以下两种方法:
this.getUserForTest = function(usedPhoneNumber, userShouldBeRegistered, done) {
userShouldBeRegistered);
getUser(usedPhoneNumber, function (isExist) {
if(isExist === !userShouldBeRegistered) {
usedPhoneNumber++;
_that.getUserForTest(usedPhoneNumber, userShouldBeRegistered, done);
} else {
_that.testedPhoneNumber = usedPhoneNumber;
console.log("found user number: " + usedPhoneNumber);
deleteUserRegistrationAttmepts(_that.testedPhoneNumber, done);
}
});
};
this.cleanUpUser = function (phone, done) {
loginUser(phone, function(userLoggedIn) {
if (userLoggedIn === true) {
getOauthToken(phone, function(gotOuth) {
if (gotOuth === true) {
deleteUser(phone, done);
}
});
}
});
};
这些方法是我们通过以下命令运行的茉莉花测试套件的一部分:
beforeEach(function (done) {
e2eHelperMethods.getUserForTest(initPhoneNumber, false, done);
browser.get(e2eHelperMethods.defaultWebsiteUri);
});
afterEach(function (done) {
e2eHelperMethods.cleanUpUser(e2eHelperMethods.testedPhoneNumber, done);
});
当我尝试加入以下两个方法时,我收到一个错误,这可能意味着我遇到了一些异步问题:
this.cleanUpAndGetTestUser = function (phone, userShouldBeRegistered, done) {
_that.cleanUpUser(phone, function(isDone) {
if (isDone === true) {
_that.getUserForTest(phone, userShouldBeRegistered, done);
}
});
};
如果有人可以指出我手边的问题,我将非常感激 - 必须有一个回调的东西,我忘了......