I need to do unit tests in JEST for a directive in Angular 1.x. Can anybody help me with an example? What I don't know is how I can access the functions from the directive to test them
This is the directive:
angular.module("SEOMod").directive("bfNewToOldTag", [
"$window",
"NavigationContext",
"ROUTE_STATES",
"$location",
"BF.SPORT",
function($window, navigationContext, ROUTE_STATES, $location, bfSport) {
"use strict";
let oldURL = navigationContext.view;
let checkIfNew = new RegExp("seo");
function getSportNameEN(id){
return bfSport.type[id].eventTypeName;
}
function getTopDomain() {
let basePath = "/exchange/plus";
return $location.protocol() +"://"+ $location.host() + (($location.port() !== 80)?":"+$location.port() : "")+basePath;
}
function appendScriptTag() { ...}
return {
restrict: "E",
replace: true,
controller() {
appendScriptTag();
}
};
}
]);
This is what I tried
describe("Seo Directive", () => {
const $window = {};
const navigationContext = {};
const ROUTE_STATES = {};
const $location = {};
const bfSport = {};
beforeEach(() => {
$location.protocol = jest.fn();
$location.host = jest.fn();
$location.port = jest.fn();
navigationContext.view = jest.fn();
});
it("should return the sport name in EN", () => {
});
});