赛普拉斯没有解析本地存储项目,尽管它显示在本地存储上
cypress not resolving localstorage item, although it shows on local storage
我正在尝试测试我的 React 应用程序。并且一些数据保存在本地存储中,我想确保它们正常工作。所以我开始用 cypress 编写测试。非常酷的库,它非常有趣,我已经编写了 ~50 个测试。但它开始显示本地存储存在问题。
我的代码:
describe("delete account",()=>{
it("delete",()=>{
cy.visit("/")
assert.equal(localStorage.getItem("---current---"), null)
const username = 'abcd1234'
cy.get('[data-cy=username-input]').click().type(username)
cy.get('[data-cy=login-button]').click()
cy.wait(4*1000)
cy.log({...localStorage})
// assert.equal(localStorage.getItem(currentPlayerLS), username)
})
})
我的目标是检查用户何时登录,获取本地存储并检查 ---current---
播放器值是否匹配。但它引发了一个异常 expected null to equal 'abcd1234'
我猜是解析有问题,所以还加了4秒的延迟
我也记录了整个{...localSotage}
说是空字典。但是本地存储说它存储了一些值。
我不知道怎么处理!!谁能帮帮我?
快照如下:
cy.log({...localStorage})
处的日志在测试运行之前采用它的值。
您应该使用它来获取登录后的值。
cy.then(() => cy.log({...localStorage}))
至于最后的断言,尝试直接使用键 ---current---
以防 currentPlayerLS
是其他东西(有些迹象表明是这样)。
assert.equal(localStorage.getItem('---current---'), username)
我正在尝试测试我的 React 应用程序。并且一些数据保存在本地存储中,我想确保它们正常工作。所以我开始用 cypress 编写测试。非常酷的库,它非常有趣,我已经编写了 ~50 个测试。但它开始显示本地存储存在问题。
我的代码:
describe("delete account",()=>{
it("delete",()=>{
cy.visit("/")
assert.equal(localStorage.getItem("---current---"), null)
const username = 'abcd1234'
cy.get('[data-cy=username-input]').click().type(username)
cy.get('[data-cy=login-button]').click()
cy.wait(4*1000)
cy.log({...localStorage})
// assert.equal(localStorage.getItem(currentPlayerLS), username)
})
})
我的目标是检查用户何时登录,获取本地存储并检查 ---current---
播放器值是否匹配。但它引发了一个异常 expected null to equal 'abcd1234'
我猜是解析有问题,所以还加了4秒的延迟
我也记录了整个{...localSotage}
说是空字典。但是本地存储说它存储了一些值。
我不知道怎么处理!!谁能帮帮我?
快照如下:
cy.log({...localStorage})
处的日志在测试运行之前采用它的值。
您应该使用它来获取登录后的值。
cy.then(() => cy.log({...localStorage}))
至于最后的断言,尝试直接使用键 ---current---
以防 currentPlayerLS
是其他东西(有些迹象表明是这样)。
assert.equal(localStorage.getItem('---current---'), username)