I have many Jasmine tests, and currently these are self-contained but often may use exactly same code (such as mocking httpBackend in some common but non-default way, or using same DTO objects for testing).
What would be the architecturally sound way to create some sort of library in this common code, using angular and jasmine?
Such as in this code snipped I indicated what I want to be in external common place - variables, functions. I could create some "dump" of such things but I prefer angular/jasmine way, if it is avaliable.
If common beforeEach/after Each can be also removed to common code place, that's even better.
describe('ProjectConfiguration controller and service Integration', function() {
var scope, $routeParams, infraService, $httpBackend, controllerToTest;
var httpBackend;
var fakeId=12;
// SUCH TEST OBJECT CAN BE MOVED TO COMMON PLACE
// SO OTHERS CAN RE-USE SHOULD THEY NEED IT
var fakedDtoBase = { // a dummy record used as a starter for faking data
Id: fakeId,
ProjectName: 'FakePrj',
ProjectDescription: 'FakePrjD',
ProjectManagerMain: 'FakePrjMM',
ProjectManagersOther: 'FakePrjOO',
ProjectStatus: 1,
ParentProjectId: null,
Deleted: 0
};
// FUNCTION INSIDE before EACH CAN BE MOVED TO COMMON PLACE
beforeEach(angular.mock.inject(function ($httpBackend) {
httpBackend = $httpBackend;
httpBackend.whenGET('Client.json').respond({
"webApiUri": "https://url:44310",
"authHeaderKey": "X-Auth-Token",
"authCookieName": "AuthCookie"
});
})
);
afterEach(function(){
// COMMON CODE INSIDE
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});