I have this testing framework and it works, but it does not apply to my requirements when I add more tests to this unit test.js file, but all related tests should go there.
WORKING
'use strict';
describe('lessonplannerFactory unit tests', function () {
var dateFactory = {
getVisibleDateRange: function (startDate, endDate, visibleWeekDays) {
var days = [ moment(new Date(2014, 0, 1)), moment(new Date(2014, 0, 2))];
return days;
}
};
beforeEach(module('clientApp', function ($provide) {
$provide.value('dateFactory', dateFactory);
}));
var lessonPlannerFactory;
beforeEach(inject(function (_lessonPlannerFactory_) {
lessonPlannerFactory = _lessonPlannerFactory_;
}));
it('creates periods by a daily rotation of n according to a given timetable for a certain timespan', inject(function (_dailyPeriodsTestDataFactory_) {
var testCases = _dailyPeriodsTestDataFactory_.testCases;
}));
});
I want this to be described in my own words or pseudo-code:
describe("lesson planner factory unit tests")
{
test1(_specificTestData1_)
{
var data = _specificTestData1_;
var stub1 = { }
inject this specific stub into this test with $provide.value = mock
var result = lessonPlannerFactory.method1(data,..);
}
test2(_specificTestData2_)
{
var data = _specificTestData2_;
var stub2 = { }
inject this specific stub into this test with $provide.value = mock
var result = lessonPlannerFactory.method2(data,..);
}
}
And this is what I tried and it does not work.
I assume that checking the stub for $ offer. The value is too late at this point inside the test, because lessonPlannerFactory is entered / created earlier, and lessonPlannerFactory has a real stub object as a dependency. Just look:
'use strict';
describe('lessonplannerFactory unit tests', function () {
beforeEach(module('clientApp'));
var lessonPlannerFactory;
beforeEach(inject(function (_lessonPlannerFactory_) {
lessonPlannerFactory = _lessonPlannerFactory_;
}));
it('creates periods by a daily rotation of n according to a given timetable for a certain timespan', inject(function (_dailyPeriodsTestDataFactory_) {
var testCases = _dailyPeriodsTestDataFactory_.testCases;
var dateFactory = {
getVisibleDateRange: function (startDate, endDate, visibleWeekDays) {
var days = [ moment(new Date(2014, 0, 1)), moment(new Date(2014, 0, 2))];
return days;
}
};
module('clientApp', function ($provide) {
$provide.value('dateFactory', dateFactory);
});
var result = lessonPlannerFactory.createPeriodsDaily(testCases[i].data1,..);
}));
});
This is the error I get:
TypeError: Cannot read property 'running' of undefined
at isSpecRunning (http:
, NOT beforeEach, INSIDE unit test, ??