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.

[Question | Bug] - getting sub injectable from TestingModule

See original GitHub issue

Hi, When trying to get a sub injectable (for example Component) it returns null. For example:

// DatabaseModule
@Module({
  modules: [],
  components: [
    SubService
  ]
})
export class AppModule {
}

// App Module
@Module({
  modules: [
    DatabaseModule
  ]
})
export class AppModule {
}

And then when trying to user createTestingModule:

const module = await Test.createTestingModule({
      modules: [AppModule]
}).compile();

const subService = appModule.get<SubService>(SubService);
concole.log(subModule) // null

I found this workaround:

const dbModule = appModule.select(DatabaseModule);
const subService = dbModule.get<SubService>(SubService);

concole.log(subService) // instance of SubService

So should the get method return also nested components of other dependent modules? If so, this is a bug.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Oct 30, 2017

Fixed, will be available in the next update. Thanks again @vlio20

1reaction
vlio20commented, Oct 29, 2017

the including imported ones is a bit misleading (maybe only for me)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I unit test a component that uses the Router in ...
createComponent(MyComponent); router = TestBed.get(Router); // TestBed.inject(Router) for Angular 9+ }); it('should navigate', () => { const component ...
Read more >
NestJS unit testing: A how-to guide with examples - Tom Ray
A deep dive tutorial into how to apply unit tests in NestJS with Jest, including how to mock with test doubles and other...
Read more >
Component testing scenarios - Angular
There can be injectors at multiple levels, from the root injector created by the TestBed down through the component tree. The safest way...
Read more >
Software Testing: 101 Top Tips, Tricks and Strategies - Stackify
Software testing is a collection of tests to determine if a software app works and will continue working. Get tips and tricks from...
Read more >
TESSY 4.1 UserManual - Razorcat
In this chapter you will get to know TESSY with the help of ... Using a cross compiler for the microcontroller in question...
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