I have tried to write jasmine unit test cases for a method which contains window.XSLTProcessor() and window.ActiveXObject().
processXmlResponse: function (xml, xsl) {
var ele = $document[0];
if (typeof ($window.XSLTProcessor) !== "undefined") {
// if condition for chrome, firefox and safari
return something;
}
else if ($window.ActiveXObject || "ActiveXObject" in $window) {
// else if condition for IE
return something;
}
}
When iam running below jasmine unit test cases it doesn't get pass through if and else if conditions.
describe('Services: xsltProcessorService', function() {
var appName = 'appName', testService, result, win, mockBackend;
beforeEach(mocks.module(appName));
beforeEach(mocks.inject(function(xsltProcessorService, $httpBackend, $window) {
testService = xsltProcessorService;
win = $window;
spyOn(win, 'XSLTProcessor').and.returnValue('str');
spyOn(xsltProcessorService, 'processXmlResponse').and.callThrough();
mockBackend = $httpBackend;
}));
it('Ensuring initialization of processXmlResponse services', function() {
testService.processXmlResponse();
expect(win.XSLTProcessor).toHaveBeenCalled();
});
});
It causes following error:
Error: XSLTProcessor() method does not exist
Is there any way to execute if and else if conditions?
Aucun commentaire:
Enregistrer un commentaire