Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectator not applied detectChanges on host component #539

Closed
ntvsx193 opened this issue Mar 24, 2022 · 1 comment
Closed

Spectator not applied detectChanges on host component #539

ntvsx193 opened this issue Mar 24, 2022 · 1 comment

Comments

@ntvsx193
Copy link
Contributor

ntvsx193 commented Mar 24, 2022

Is this a regression?

Yes

Description

import { Component, Input } from '@angular/core';
import { createComponentFactory, Spectator } from '@ngneat/spectator';

@Component({
  selector: 'app-foo',
  template: '',
  host: {
    '[class.bar]': 'bar'
  }
})
class FooComponent {
  @Input() bar: boolean;
}

describe('FooComponenent', () => {
  const createComponent = createComponentFactory({
    component: FooComponent
  });

  let spectator: Spectator<FooComponent>;

  beforeEach(() => {
    spectator = createComponent();
  });

  it('should set the class name "bar"', () => {
    spectator.setInput({ bar: true });

    expect(spectator.element).toHaveClass('bar');
  });
});

We catch error after run this spec:

Error: Expected element to have class 'bar', but had 'undefined'
	    at <Jasmine>
	    at UserContext.eval (webpack-internal:///94564:35:35)
	    at ZoneDelegate.invoke (webpack-internal:///23484:461:160)
	    at ProxyZoneSpec.onInvoke (webpack-internal:///83761:341:35)

For local fix in the current test, we need add spectator.detectChanges() after spectator.setInput ... for trigger root DC.

Some time ago, I'm open PR with fix these problems

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

Yes

@michelmeeuwissen
Copy link

Because of this change you will have to set all input change at once.

spectator.setInput({
  'type1': type.ABC,
  'type2':  type.CDE,
   'type2':  type.FGH,
});

Otherwise you can have read properties of undefined erros

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants