mercredi 25 février 2015

Unknown Provider when unit testing filter

I am unit testing my first filter, which seems easy enough but I keep getting



Unknown provider: activeProfileProvider <- activeProfile <- pbRoles <- rolesFilter



The activeProfile is a consent that is a dependency of pbRoles. My understanding of constants is limited and I cant seem to find a way to include it. I have tried adding the config file where the constants are declared as well as mocking the constant in the test to no avail.


does anyone know if there is a specific way to do this? or does my problem lay else where?


My filter:



angular.module('pb.roles.filters')
.filter('roles', ['pbRoles', function (pbRoles) {
return function (input) {
if (!input) {
return "None";
} else {
return pbRoles.roleDisplayName(input);
}
};

}]);


My test:



describe('RolesController', function () {

beforeEach(module('pb.roles'));
beforeEach(module('pb.roles.filters'));
beforeEach(module('ui.router'));
beforeEach(module('ui.bootstrap'));

var rolesFilter;
var mockActiveProfile = {};

beforeEach(inject(function (_rolesFilter_) {
activeProfile = mockActiveProfile;
rolesFilter = _rolesFilter_;
}));

var pbRoles = {
roleDisplayName: function (input) {
return input
}
};

describe('role: filter', function () {

it('should return None if called with no input', function () {
expect(rolesFilter()).toBe('None');
});

it('should call roleDisplayName with input', function () {
expect(roles('Hello')).toBe('Hello');
});
});

});

Aucun commentaire:

Enregistrer un commentaire