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

Schematics: Use MockStore in container generated tests #2028

Closed
jtcrowson opened this issue Jul 21, 2019 · 0 comments · Fixed by #2029
Closed

Schematics: Use MockStore in container generated tests #2028

jtcrowson opened this issue Jul 21, 2019 · 0 comments · Fixed by #2029

Comments

@jtcrowson
Copy link
Contributor

The test file generated by the container schematic is currently importing the StoreModule:

// ...
import { Store, StoreModule } from '@ngrx/store';

describe('ExampleComponent', () => {
  // ...
  let store: Store<any>;

  beforeEach(async() => {
    TestBed.configureTestingModule({
      imports: [ StoreModule.forRoot({}) ], // <--- Outdated
      declarations: [ ExampleComponent ]
    });

    await TestBed.compileComponents();
  });

  beforeEach(() => {
    // ...
    store = TestBed.get<Store>(Store);

    spyOn(store, 'dispatch').and.callThrough();
    fixture.detectChanges();
  });
  // ...
});

Instead, the schematic should use MockStore:

// ...
import { provideMockStore, MockStore } from '@ngrx/store/testing';

describe('ExampleComponent', () => {
  // ...
  let store: MockStore<any>;

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

    await TestBed.compileComponents();
  });

  beforeEach(() => {
    // ...
    store = TestBed.get(Store);
    fixture.detectChanges();
  });
  // ...
});

If accepted, I would be willing to submit a PR for this feature

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

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

Successfully merging a pull request may close this issue.

2 participants