question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MockBuilder add import

See original GitHub issue

Hello again !

First of all, do you have a Gitter or a Discord to ask this kind of question and avoid creating issues every time ?

We are trying to use MockBuilder, it looks great!

But, we are unable to import unmocked modules that are not part of the component module.

Here the original TestBed:

TestBed.configureTestingModule({
  declarations: [
    MyComponent,
    MockComponents(MatToolbar, MatIcon),
    MockDirective(MatIcon)
  ],
  imports: [
    // StoreModule come from App top Module
    StoreModule.forRoot(reducers, { runtimeChecks: environment.storeRuntimeChecks }),
    StoreModule.forFeature(featureReducers.featureKey, featureReducers.reducer)
  ],
  providers: [
    { provide: MyService, useValue: mockMyService },
  ],
})

Here the equivalent with MockBuilder:

MockBuilder(MyComponent, ItsModule)
      // I tried this but it doesn't work
      .keep(StoreModule.forRoot(reducers, { runtimeChecks: environment.storeRuntimeChecks }))  // Try also , { export: true }
      .keep(StoreModule.forFeature(featureReducers.featureKey, featureReducers.reducer)) // Try also , { export: true }
      .mock(MyService)

Can you help me on that ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kekel87commented, Oct 15, 2020

Sorry for late response ! It’s work perfectly, thanks a lot !

1reaction
satanTimecommented, Oct 9, 2020

Hi @kekel87,

might you verify that both of the issues are properly solved here: ng-mocks.zip?

now you can keep and mock modules with providers and pass anywhere abstract classes like DomSanitizer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MockBuilder add import · Issue #197 · help-me-mom/ng-mocks
We are trying to use MockBuilder , it looks great! But, we are unable to import unmocked modules that are not part of...
Read more >
MockBuilder - the simplest way to create mocks in Angular tests
MockBuilder - the simplest way to create mocks in Angular tests. ... Modules are added as imports to the MyModule .
Read more >
ng-mocks/community - Gitter
Hi guys. I'm trying to test a route resolver and everything seems to be working fine for the successful resolve, but for unsuccessful...
Read more >
ng-mocks - npm
An Angular testing library for creating mock services, components, directives, pipes and modules in unit tests.
Read more >
ES6 Class Mocks - Jest
Jest can be used to mock ES6 classes that are imported into files you want to test.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found