I have a JSON which I am supposed to use to write a unit test. It looks like
angular.module('mySvcMock', [])
.value('studentMockJSON',
[
{
"username": "student1",
"firstName": "student"
}
]
)
.value('teacherMockJSON',
[
{
"username": "teacher1",
"firstName": "teacher",
}
]
);
and here is my controller
describe('Data Service', function () {
var expect = chai.expect,
$httpBackend,
myDataSvc,
provide;
beforeEach(function () {
var appRoleMock = 'Teacher',
urlAPISvcMock,
userSvcMock;
urlAPISvcMock = {
getAPIurl: function (apiString) {
return 'http://localhost:8080' + apiString;
},
getFirstSubdomain: function () {
}
};
userSvcMock = {
getId: function () {
return 1;
}
};
module('myDataServices', 'mySvcMock');
module(function ($provide) {
provide = $provide;
$provide.value('appRole', appRoleMock);
});
module(function ($provide) {
$provide.value('urlAPISvc', urlAPISvcMock);
});
module(function ($provide) {
$provide.value('myDataUserSvc', userSvcMock);
});
inject(function (_myDataSvc_, $injector, studentMockJSON) {
myDataSvc = _myDataSvc_;
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET(urlAPISvcMock.getAPIurl("/rest/report/student")).respond(200, studentMockJSON);
});
});
I need to run same set of tests on both JSON values with different appRole values - teacher and principal. I have tried using data providers to achieve it and it did not work. I would hate to make two different specs just for the appRole change. Any suggestions on how to make this work? Best possible scenario would be that the role is set in each test.