Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

feat: add selector #144

Merged
merged 1 commit into from
Dec 29, 2019
Merged

Conversation

aymeric-duchein
Copy link
Contributor

This is a proposition regarding those issues: #3 and #4 .

If this looks good, I'll add the docs. For now you can find an exemple in the spec.ts file.

This allow you to mock every selector* using the mockSelect function. It returns a Subject for each selector allowing you to control in wich order, when and what each selector should emit.
You'll still need to import the NgxsModule.forRoot() module in the Testbed (you'll most likely need it anyway if your component dispatch anything to the store 😉 ) .

*Selectors with parameters should be exported into constant beforehand as function comparison won't recognise them otherwise

@splincode
Copy link
Member

What do you think about?

import { mockSelect } from '@ngxs-labs/testing/jest'; // sub package for jest

beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [HostComponent],
            imports: [CommonModule, NgxsModule.forRoot([ZooState])]
        }).compileComponents();

        foodSelector$ =mockSelect(ZooState.feed);
        animalsSelector$ =mockSelect(ZooState.animals);

        fixture = TestBed.createComponent(HostComponent);
        component = fixture.componentInstance;

        fixture.detectChanges();
    });

@aymeric-duchein
Copy link
Contributor Author

What do you think about?

import { mockSelect } from '@ngxs-labs/testing/jest'; // sub package for jest

beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [HostComponent],
            imports: [CommonModule, NgxsModule.forRoot([ZooState])]
        }).compileComponents();

        foodSelector$ =mockSelect(ZooState.feed);
        animalsSelector$ =mockSelect(ZooState.animals);

        fixture = TestBed.createComponent(Hostponent);
        component = fixture.componentInstance;

        fixture.detectChanges();
    });
`

This would be cleaner indeed, a jasmine version would be nice to have now that you mention subpackaging

@splincode
Copy link
Member

@aymeric-duchein any progress?

@aymeric-duchein
Copy link
Contributor Author

Updated with the new Jest sub-package.

src/lib/ngxs.setup.ts Outdated Show resolved Hide resolved
src/tests/ngxs.setup.spec.ts Outdated Show resolved Hide resolved
@splincode splincode merged commit b3ad5e8 into ngxs-labs:master Dec 29, 2019
@aymeric-duchein aymeric-duchein deleted the feat_mock_select branch December 29, 2019 13:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants