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

fix(store): provide the same instance of MockStore #2381

Merged
merged 3 commits into from
Feb 14, 2020

Conversation

lacolaco
Copy link
Contributor

@lacolaco lacolaco commented Feb 14, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Currently, TestBed.inject(Store) returns a different instance to TestBed.inject(MockStore). So the test below fails.

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AppComponent],
      providers: [
        provideMockStore(),
      ]
    }).compileComponents();
  }));

  it("mockstore providers", () => {
    const storeA = TestBed.inject(Store);
    const storeB = TestBed.inject(MockStore);
    expect(storeA).toBe(storeB); // => FAIL
  });

Users expect they are the same because it is mocking.

What is the new behavior?

It solved.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Angular CLI: 9.0.2
Node: 12.13.0
OS: darwin x64

Angular: 9.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.2
@angular-devkit/build-angular     0.900.2
@angular-devkit/build-optimizer   0.900.2
@angular-devkit/build-webpack     0.900.2
@angular-devkit/core              9.0.2
@angular-devkit/schematics        9.0.2
@angular/cli                      9.0.2
@ngtools/webpack                  9.0.2
@schematics/angular               9.0.2
@schematics/update                0.900.2
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

@ngrxbot
Copy link
Collaborator

ngrxbot commented Feb 14, 2020

Preview docs changes for 1a5935e at https://previews.ngrx.io/pr2381-1a5935e/

@alex-okrushko
Copy link
Member

Thanks @lacolaco !

@alex-okrushko
Copy link
Member

Actually, would you mind adding that test to https:/ngrx/platform/blob/master/modules/store/testing/spec/mock_store.spec.ts ?

@lacolaco
Copy link
Contributor Author

@alex-okrushko Sure! wait a moment plz 😉

@timdeschryver timdeschryver changed the title fix(store/testing): provide the same instance of MockStore fix(store): provide the same instance of MockStore Feb 14, 2020
@timdeschryver timdeschryver merged commit 827f336 into ngrx:master Feb 14, 2020
@timdeschryver
Copy link
Member

Thanks @lacolaco !

@mjudde
Copy link

mjudde commented Apr 17, 2020

Would it be possible to have this fix on NGRX 8.6 ?

@alex-okrushko
Copy link
Member

@brandonroberts WDYT?

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

Successfully merging this pull request may close these issues.

5 participants