Created
April 6, 2015 16:24
-
-
Save trodrigues/6cbe73943baae57e2e2a to your computer and use it in GitHub Desktop.
Mocking all sorts of stuff in angular (assumes lodash exists)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mocks = angular.module('yourapp/mocks', []); | |
mocks.config(['$provide', '$controllerProvider', function ($provide, $controllerProvider) { | |
$provide.stubDirective = function (name, definition) { | |
$provide.factory(name + 'Directive', function () { | |
return [_.extend({ | |
name: name, | |
restrict: 'A', | |
priority: 0, | |
}, definition)]; | |
}); | |
}; | |
$provide.removeDirectives = function () { | |
_.flatten(arguments).forEach(function (directive) { | |
var fullName = directive + 'Directive'; | |
$provide.factory(fullName, function () { | |
return []; | |
}); | |
}); | |
}; | |
$provide.removeController = function (label, fakeController) { | |
$controllerProvider.register(label, fakeController || angular.noop); | |
}; | |
$provide.removeControllers = function () { | |
_.flatten(arguments).forEach(function (controller) { | |
$controllerProvider.register(controller, angular.noop); | |
}); | |
}; | |
$provide.stubFilter = function (filterName, returnValue) { | |
$provide.value(filterName+'Filter', function () {return returnValue || '';}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment