程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了稍后将变量重用为整数/文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决稍后将变量重用为整数/文本?

开发过程中遇到稍后将变量重用为整数/文本的问题如何解决?下面主要结合日常开发的经验,给出你关于稍后将变量重用为整数/文本的解决方法建议,希望对你解决稍后将变量重用为整数/文本有所启发或帮助;

我曾尝试让 cypress 保存文本以备后用,但我觉得无法将其作为变量重用

cy.get('.unrd').then(($span) => {
  const filteredunread = $span.text()
  cy.wrap(filteredunread).as('oldunreadmessage');
})

发送邮件、等待并返回收件箱等待回显回复的代码块

cy.get('.unrd').then(($span) => {
  cy.get('@oldunreadmessage') //seen as object
  const newunread = $span.text()
  expect(newunread).to.eq(cy.get('@oldunreadmessage') +1)
})

这给了我以下错误:

expected '(27)' to equal '[object Object]1'

我曾尝试使用 .as()。但是,我似乎无法将旧对象正确解析为文本或整数常量。

解决方法

第一部分很好,但由于 cy.wrap,您需要在 should 上使用 thency.get('@oldunreadmessage')

cy.get('.unrd').then(($span) => {
    const newunread = $span.text();
    cy.get('@oldunreadmessage').should('have.text',newunread);
})

cy.get('.unrd').then(($span) => {
    const newunread = $span.text();
    cy.get('@oldunreadmessage').then((oldunread) => {
        expect(newunread)...
    }
})

大佬总结

以上是大佬教程为你收集整理的稍后将变量重用为整数/文本全部内容,希望文章能够帮你解决稍后将变量重用为整数/文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: