在detectChanges之后,主机绑定不会更新

时间:2017-11-15 08:27:46

标签: angular

我有以下测试

it('test', function(){
  @Component({
     host: {
        '[style.display]': 'service.obj.value ? "inline-block" : "none"'
     }
  })
  class Component{
     ...
  }

  TestBed.configureTestingModule({
    declarations: [
      Component
    ],
    providers: [
      {
        provide: InjectedService,
        useValue: {
          obj: this.obj
        }
      }
    ]
  });

  this.fixture.detectChanges();
  expect(this.de.styles.display).toBe('none');

  this.obj.value = 'value';
  this.fixture.detectChanges();
  expect(this.de.styles.display).toBe('inline-block');
})

第二种期望失败,因为风格不会重新出现。

为什么呢?两种情况下初始值都是正确的

0 个答案:

没有答案
相关问题