Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jasmine中的每个函数之后调用descripe或it函数_Javascript_Angular_Unit Testing_Jasmine - Fatal编程技术网

Javascript 如何在jasmine中的每个函数之后调用descripe或it函数

Javascript 如何在jasmine中的每个函数之后调用descripe或it函数,javascript,angular,unit-testing,jasmine,Javascript,Angular,Unit Testing,Jasmine,我想在每次itfunction之后检查按钮禁用状态。因此,我在每个函数之后都使用,但出现了如下错误。 如何在每个函数或任何工作区域后调用描述或它函数 'it' should only be used in 'describe' function description('输入错误检查',()=>{ const fixture=TestBed.createComponent(AppComponent); 之后(()=>{ const searchButon=fixture.debugElemen

我想在每次
it
function之后检查按钮禁用状态。因此,我在每个函数之后都使用
,但出现了如下错误。
如何在每个函数或任何工作区域后调用
描述
函数

'it' should only be used in 'describe' function
description('输入错误检查',()=>{
const fixture=TestBed.createComponent(AppComponent);
之后(()=>{
const searchButon=fixture.debugElement.query(By.css(“#searchButton”)).nativeElement作为HTMLButtoneElement
expect(searchButon.disabled).toBeTruthy()
})
它('无输入值',()=>{
//编写测试代码
})
它('无效输入值',()=>{
//编写测试代码
})
})

每次
后的
方法仅用于拆卸逻辑:

在中描述的每个规格后运行一些共享拆卸 这就是所谓的

您可以在每个测试结束时添加此expect,生成一个小型代理,如下面的代码所示:

function withSearchButtonDisabled(testCallback) {
   return () => {
      testCallback();
      const searchButon = fixture.debugElement.query(By.css('#searchButton')).nativeElement as HTMLButtonElement
      expect(searchButon.disabled).toBeTruthy()
   }
}

  describe('Input Error Check', () => {
    const fixture = TestBed.createComponent(AppComponent);

    it('No Input Value', withSearchButtonDisabled(() =>{
      // write test code
    }))


    it('Invalid Input Value', withSearchButtonDisabled(() =>{
      // write test code
    }))
    
  })
PS我没有测试代码,可能有输入错误