Testing Controllers with Injected Services
See original GitHub issuehi.
In the spec example of “home” component, a controller is created with the new operator.
what if, a controller is injected with services?
how should that be addressed?
i.e.:
// Given the controller is injected with these:
class HomeController {
constructor(Users, $http, $stateParams) {
this.name = 'home';
}
}
export default HomeController;
Should I use the $controller in the injector?
beforeEach(inject((_$rootScope_, $controller) => {
$rootScope = _$rootScope_;
scope = $rootScope.$new();
makeController = () => {
return $controller('HomeController as vm', { $scope: scope });
};
}));
Thanks.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6
Top Results From Across the Web
Unit Testing With Dependency Injection On controller
I want to test my modification to AccountController (asp.net core 2 mvc) i use a repository to put logic this repo. The problem...
Read more >Unit test controller logic in ASP.NET Core - Microsoft Learn
Set up unit tests of controller actions to focus on the controller's behavior. A controller unit test avoids scenarios such as filters, routing, ......
Read more >Testing Controllers with Unit Tests and Moq in ASP.NET Core -
In this article, we are going to talk about unit testing controllers by using the Moq library, which enables us to isolate dependencies....
Read more >Testing your controllers when you have a decoupled core
We need a way to inject this mock into the controller as a constructor argument. This should only happen when the controller is...
Read more >How to test a controller with a service that has @Inject in its ...
I have a question regarding testing as described on https://docs.nestjs.com/advanced/unit-testing: beforeEach(async () => { const module ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@orizens , like @fesor said will be something like this:
@blackendstudios Thanks.