I am currently trying to test out view1(home.js) and in view1, I use filters and directives that I moved from the view1_test.js to the app.js level. All of my tests use to pass and now anything referencing the filters or directives now fail their tests. I was wondering do I need to create an app_test.js or is there a way to fix the tests to still work? Below is an example of what I am talking about.
app.js
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.home',
'ngAnimate',
'ui.bootstrap',
'ui.date'
]).
config(['$routeProvider','$httpProvider','$locationProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/home'});
}])
.filter('upper', function () {
return function (input) {
return input.toUpperCase();
};
})
view1.js(home.js)
'use strict';
angular.module('myApp.home', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/home', {
templateUrl: 'home/home.html',
controller: 'HomeCtrl'
});
}])
view1_test.js(home_test.js)
'use strict';
describe('myApp.home module', function () {
beforeEach(module('myApp.home'));
}
describe('Filter: upper', function () {
var upperFilter;
beforeEach(inject(function (_upperFilter_) {
upperFilter = _upperFilter_;
}));
it('should be able to uppercase an entire input', function () {
expect(upperFilter('hello')).toBe('HELLO');
expect(upperFilter('hello world')).toBe('HELLO WORLD');
});
});
While running this test. I get this:
Chrome 47.0.2526 (Windows 7 0.0.0) myApp.home module Filter: upper should be able to uppercase an entire input FAILED Error: [$injector:unpr] Unknown provider: upperFilterProvider <- upperFilter http://errors.angularjs.org/1.4.7/$injector/unpr?p0=upperFilterProvider%20%3C-%20upperFilter at C:/webroot/member_portal/app/bower_components/angular/angular.js:68:12 at C:/webroot/member_portal/app/bower_components/angular/angular.js:4289:19 at Object.getService [as get] (C:/webroot/member_portal/app/bower_components/angular/angular.js:4437:39) at C:/webroot/member_portal/app/bower_components/angular/angular.js:4294:45 at getService (C:/webroot/member_portal/app/bower_components/angular/angular.js:4437:39) at Object.invoke (C:/webroot/member_portal/app/bower_components/angular/angular.js:4469:13) at Object.workFn (C:/webroot/member_portal/app/bower_components/angular-mocks/angular-mocks.js:2438:20) Error: Declaration Location at window.inject.angular.mock.inject (C:/webroot/member_portal/app/bower_components/angular-mocks/angular-mocks.js:2409:25) at Suite. (C:/webroot/member_portal/app/home/home_test.js:766:20) at Suite. (C:/webroot/member_portal/app/home/home_test.js:763:5) at C:/webroot/member_portal/app/home/home_test.js:3:1 TypeError: upperFilter is not a function at Object. (C:/webroot/member_portal/app/home/home_test.js:771:20) Chrome 47.0.2526 (Windows 7 0.0.0): Executed 1 of 54 (1 FAILED) (skipped 53) ERROR (0.327 secs / 0.005 secs)