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.

typedefinition: TestBed.inject(T) should return jasmine.SpyObj<T>

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/....

@angular/core testing I was playing with the test project of Angular and I noticed that the TestBed.inject(service) method is returning the service whereas it should be returning a jasmine.SpyObj<service> Can you check the type definition of the method please or maybe I misunderstood the definition?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bryanforbescommented, Mar 23, 2020

I’m trying to do something similar to the code in the test project and I’m getting a compiler error when I try to assign TestBed.inject(ValueService) to valueServiceSpy. And it really should be a compiler error. The only reason the StackBlitz demo works is because the compiler can’t find a definition for jasmine.SpyObj, so it sets the type of valueServiceSpy to any and then allows the assignment. Unless I’m missing some sort of compiler flag in my project that adds logic to the compiler to add additional type info to TestBed.inject() after a TestBed.configureTestingModule(), the code in the demo project won’t compile in a normal environment.

0reactions
angular-automatic-lock-bot[bot]commented, May 14, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular TestBed.inject type error when injecting into a spy
Seems to be bad function typing by Angular, as the .inject() returns T and not SpyObj<T> . But thank you for the valid...
Read more >
Testing Dependency Injection β€’ Angular - codecraft.tv
When the component is created since it has its own injector it will resolve the AuthService itself and not forward the request to...
Read more >
8. Mocking the injected service using createSpyObj method ...
In this video we will see how to mock the injected service using jasmine.createSpyObj method and spy on the mocked service methodΒ ...
Read more >
28. Create instance for the Services using Test Bed inject ...
In this video we will see how to create instance for the services using the Test Bed Inject Method - Angular Unit Testing....
Read more >
https://raw.githubusercontent.com/ngneat/spectator...
Changelog All notable changes to this project will be documented in this file. ... spectator - This method taps into the type safe...
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