I need to write a unit test for a JavaScript function within an Angular service using Jasmine.
Here is the Angular service:
angular.module("app.services").service("validationService", ["$q", function ($q) {
this.validate = function (filter): ng.IPromise<any> {
let defer = $q.defer();
defer.resolve(validateOrder(filter.valA, filter.valB);
return defer.promise;
};
function validateOrder = (valueA, valueB) {
return valueA > valueB;
};
}]);
This is my current unit test:
"use strict";
describe("Service: validationService -> ", function () {
// load the service"s module
beforeEach(module("app.services"));
var validationService;
beforeEach(inject(function ($injector) {
validationService = $injector.get("validationService");
}));
it("should call validateOrder and return false", function() {
// Arrange
var filter = {"valA": 10, "valB": 100};
// Act and Assert
expect(validationService.validateOrder(filter.valA, filter.valB)).toEqual(false);
});
});
I am looking to test the function named "validateOrder" while converting it into a this.validateOrder function. How can I achieve this while keeping it as a standalone function?