My logout function sends a request to the logout api and clears all cookies effectively ending the session. It works really well but when I run the function in test, I get:
ReferenceError: $ is not defined
I know this comes from when, in the logout function, I try to clear all of my cookies by running:
for(var cookie in $.cookie()) {
$.removeCookie(cookie);
}
Thanks for taking a look! The rest of the code is below:
Controller
simulatorApp.controller('homeController', function homeController($scope, $http, $cookies, localAPI) {
$scope.logout = function() {
var logoutRequest = {
method: 'POST',
url: localAPI.url + 'auth/logout/',
headers: requestHeaders
};
$http(logoutRequest);
for(var cookie in $.cookie()) {
$.removeCookie(cookie);
}
};
Test
describe('homeController', function() {
beforeEach(module('simulatorApp'));
var controller;
beforeEach(inject(function(_$controller_) {
controller = _$controller_;
}));
var $scope = {};
beforeEach(inject(function($controller, $httpBackend) {
$httpBackend.whenPOST("http://0.0.0.0:8000/api/logout/").respond("Good for you");
controller('homeController', {
$scope: $scope
});
$scope.logout();
$httpBackend.flush()
}));
});