I do not have much of experience with jasmine. Am trying to test the nv.d3 addGraph function but the function doesn't seem to get called. I am not sure what am I missing. Any help will be greatly appreciated!! Thanks in advance.
angular.module('test.addGraph', []).factory('displayCharts', function() {
nv.addGraph(function() {
var chart = nv.models.lineChart().margin({
left: 30, right: 30
}).useInteractiveGuideline(false).interactive(false).transitionDuration(350).showYAxis(true).showXAxis(true);
var maxTicks = 3;
..........
describe('Unit Test: chart service', function(){
var mockAddGraph, scope, data, id, chartType, d3Spy;
beforeEach(module(''test.addGraph'));
beforeEach(function() {
data = [{"data1": "1424178000000","data2": "100"}];
id = "utilChart";
chartType = "performance";
});
beforeEach(inject(function($injector, $rootScope, $q) {
mockAddGraph= $injector.get('displayCharts');
scope = $rootScope.$new();
//mock get element by id
var mockHTML = document.createElement('svg');
document.getElementById = jasmine.createSpy("HTML Element").and.returnValue(mockHTML);
}));
it('unit test for renderUtilChart', function() {
expect(mockAddGraph).toBeDefined();
var d3Spy = jasmine.createSpyObj('nv', ['addGraph']);
spyOn(nv, 'addGraph').and.returnValue(d3Spy);
});
});