Я потратил довольно много времени, ударяя головой о попытку переопределить введенные константы, предоставляемые в конфигурационные функции модулей. Мой код выглядит примерно как
common.constant('I18n', <provided by server, comes up as undefined in tests>);
common.config(['I18n', function(I18n) {
console.log("common I18n " + I18n)
}]);
Наш обычный способ гарантировать, что I18n вводится в наши модульные тесты, - это сделать
module(function($provide) {
$provide.constant('I18n', <mocks>);
});
Это отлично работает для моих контроллеров, но похоже, что функция config не смотрит на то, что $provide
d вне модуля. Вместо того, чтобы получать издеваемое значение, оно получает более раннее значение, определенное как часть модуля. (Undefined в случае наших тестов, в нижнем плункере, 'foo'.)
Рабочий плункер находится ниже (смотрите консоль); кто-нибудь знает, что я делаю неправильно?