In Angular unit testing, it takes a lot of unnecessary code to mock/stub all depencencies manually, especially when all I need are some generic mocks. Also, when dependency list changes for service/controller, tests break because of missing dependencies.
In C#, there is a way to reconfigure DI container to automatically mock all dependencies, when Resolve() is called. I want something like that in Angular.
I want to go from this:
beforeEach(inject(function ($controller, $rootScope, agsRest) {
scope = $rootScope.$new();
sut = $controller('SearchController', {
$scope: scope
, map: {}
, agsRest: agsRest
, config: {}
, core: {}
, myPopup: {}
, popupFormatter: {}
});
}));
To something like this:
beforeEach(inject(function ($controller, $rootScope, agsRest) {
scope = $rootScope.$new();
sut = autoMock("SearchController"); // instance of SearchController is returned, which has all dependencies mocked with sinon/jasmine/whatever
}));
Is there some kind of library / code to do this?
Aucun commentaire:
Enregistrer un commentaire