代码之家  ›  专栏  ›  技术社区  ›  Samuel

fixture.whenstable()从角度4升级到6后停止工作/调用

  •  0
  • Samuel  · 技术社区  · 6 年前

    所以我很少有测试用例检查组件的一些属性(比如button)。

    早些时候,我有一些测试用例,这些测试用例通常工作如下:

                fixture.whenStable().then(()=>{
                    const nextBtn = fixture.debugElement.nativeElement.querySelector(
                        '#create-btn'
                    );
                    console.log(nextBtn)
                    expect(nextBtn.getAttribute('ng-reflect-disabled')).toBe('true');;
                })
    

    突然之间,密码不进去了 fixture.whenStable().then(() => {}) ,测试用例通过时会发出警告,如

    某个组件应该禁用按钮,但没有预期

    我在网上找不到任何东西。有没有人遇到过类似的问题。

    我还试着把它包起来 async() 属于 it 但没有运气

    1 回复  |  直到 6 年前
        1
  •  0
  •   R. Viral    6 年前

    你可以试试下面的东西。

    it('TEST', async(() => {
        fixture.whenStable().then(() => {
            fixture.detectChanges(); // you can write this
            const nextBtn = fixture.debugElement.nativeElement.querySelector('#create-btn');
            expect(nextBtn.getAttribute('ng-reflect-disabled')).toBe('true');
        });
    }));