TypeError '2019' 不可用

TypeError '2019' is not thenable

我想用量角器创建一个黄瓜测试步骤,但我在预期步骤中遇到了“2019”不可用。 这是我的源代码:

        this.Then(/^I check that the calculated year from the current month\(if current month >= 6 ==> current year = current year \+ 2,else current year = current year \+ 1\)$/,function(callback) {

            var actualDate=new Date();
            var actualYear=actualDate.getFullYear();
            var actualMonth=actualDate.getMonth()+1;
            //expect(targetAmountPO.getYesInflationLabel().isDisplayed()).eventually.to.equal(true).then(callback);
            targetAmountPO.getYesInflationLabel().isDisplayed().then(function() {
                targetAmountPO.getYesInflationCorrectionAnswer().isSelected().then(function(){
                    targetAmountPO.getYesInflationLabel().getAttribute("outerText").then(function(text,callback){
                        //console.log(text);
                        var splittedString=text.split(":");
                        //console.log(splittedString[1]);
                        if(actualMonth>=6)
                        {
                            actualYear+=2;
                            var yearString=actualYear.toString();
                            console.log(yearString);
                             expect(yearString).to.eventually.contain(splittedString[1]).and.notify(callback);

                            //console.log(actualYear);

                        }
                        else
                        {
                             expect(actualYear+1).to.include(splittedString[1]).and.notify(callback);

                        }

                })

                })

            })


        })

在 expect(yearString).to.eventually.contain(splittedString[1]).and.notify(callback);

我收到“2019”不可用。 yearString 是 2019 很好。 但是为什么不可以呢?

你能帮帮我吗?

由于您已正确处理 getAttribute("outerText") 返回的承诺,因此 yearStringsplittedString 中的值只是实际值而不是承诺,因此您可以使用 chai 断言和不是像

这样承诺的断言
expect(yearString).to.contain(splittedString[1])
callback()

你将能够测试它以确保它不会在断言实际进行检查之前回调