【问题标题】:How to Access NgRX state in Cypress Test如何在赛普拉斯测试中访问 NgRX 状态
【发布时间】:2022-12-10 05:10:45
【问题描述】:

在 Angular 应用程序中,我想访问 Cypress 测试中的 App State。

我遵循了以下建议: How to use Angular Store in Cypress e2e tests

到目前为止没有任何效果。我目前的设置:

export interface IWindowCypress {
  store: Store;
  Cypress: unknown;
}
export class AppComponent {
  constructor(protected store: Store) {
    const windowWithStore: IWindowCypress = window as unknown as IWindowCypress;
    console.log('AppComponent');
    if (windowWithStore.Cypress) {
      console.log('save store');
      windowWithStore.store = store;
    }
  }
}

在柏树边,

describe('My First Test', () => {
  before(() => {
    cy.window().its('store').should('have.length', 6)
  })

此设置没有类型错误。但是在 Cypress 测试中,cy.window.store 不存在。我试过传递一个数组而不是一个商店,甚至在赛普拉斯方面也不存在。关于如何解决此问题的任何想法?

【问题讨论】:

    标签: angular cypress ngrx ngrx-store


    【解决方案1】:

    您错过了一个步骤,应该通过this 引用组件属性

    if (windowWithStore.Cypress) {
      windowWithStore.store = this.store;
    }
    

    看起来您正在使用的参数版本在组件初始化后被销毁。

    【讨论】:

      猜你喜欢
      • 2020-05-02
      • 2021-10-20
      • 1970-01-01
      • 2023-02-18
      • 2021-06-13
      • 2023-02-14
      • 1970-01-01
      • 2021-11-06
      • 2020-05-16
      相关资源
      最近更新 更多