3

I have the following test

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');
})

Second expectation failed, because style does not rerender.

Why? Initial value rendered correct for both cases

Valery Kozlov
  • 1,557
  • 2
  • 11
  • 19
  • This question here addresses this issue: https://stackoverflow.com/questions/50137734/detectchanges-not-working-within-angular-test – Techgeekster Mar 14 '19 at 17:16

0 Answers0