You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer, I would like to write an integration test that asserts that I've properly passed my State data down into a subcomponent. Specifically, I would optionally like to be able to test additional cases surrounding what happens if I want to try different types of data configurations passed into a subcomponents input or an *ngIf on a component in a container template.
Use case
As a trivial example, assume the following component setup and template:
describe('MyFormContainer',()=>{letcomponent: MyFormContainer;letfixture: ComponentFixture<MyFormContainer>;letmockStore: MockStore<State>;letform: MyFormComponent;letformDe: DebugElement;letformErrors: MemoizedSelector<object,string[]>;beforeEach(async(()=>{TestBed.configureTestingModule({imports: [MyFormComponentModule],declarations: [MyFormContainer],providers: [provideMockStore()],schemas: []}).compileComponents();}));beforeEach(()=>{fixture=TestBed.createComponent(MyFormContainer);component=fixture.componentInstance;mockStore=TestBed.get(Store);spyOn(mockStore,'dispatch');formErrors=mockStore.overrideSelector(selectFormErrorsState,[]);fixture.detectChanges();formDe=fixture.debugElement.query(By.css('my-form'));form=formDe.componentInstance;});it('should compile',()=>{expect(form).toBeTruthy();});it('should set the `errors` input on `my-form`',()=>{mockStore.resetSelectors();formErrors.release();formErrors=mockStore.overrideSelector(selectFormErrorsState,['an error']);formErrors.setResult(['an error'])fixture.detectChanges();expect(form.errors).toEqual(['an error']);});});
Specifically, look at the above test. Ideally, I'd like to assert that if the state of the selectFormErrorsState selector changes, then so does the property errors on the my-form component.
Currently, the output is:
Expected $.length = 0 to equal 1.
Expected $[0] = undefined to equal 'an error'.
I think the issue at hand is that the Store observable isn't updating a new state, but I even tried to forcibly do that via MockStore#setState but to no avail;
Notes
While this is a trivialized use-case, I plan on using this in various situations, and currently, doing so is pretty frustrating even in the above case.
I would be willing to submit a PR for the docs ❤️
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered:
Other information:
@brandonroberts new
MockStore.overrideSelectors
API needs further documentation, as using it is a bit of a pain at the moment.#915 #1504 #1688 #1761
Goal
As a developer, I would like to write an integration test that asserts that I've properly passed my State data down into a subcomponent. Specifically, I would optionally like to be able to test additional cases surrounding what happens if I want to try different types of data configurations passed into a subcomponents
input
or an*ngIf
on a component in a container template.Use case
As a trivial example, assume the following component setup and template:
Template
Component Definition(Container)
Container Spec
Specifically, look at the above test. Ideally, I'd like to assert that if the state of the
selectFormErrorsState
selector changes, then so does the propertyerrors
on themy-form
component.Currently, the output is:
I think the issue at hand is that the
Store
observable isn't updating a new state, but I even tried to forcibly do that viaMockStore#setState
but to no avail;Notes
While this is a trivialized use-case, I plan on using this in various situations, and currently, doing so is pretty frustrating even in the above case.
I would be willing to submit a PR for the docs ❤️
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: