JSFiddle - React, Tailwind, and code Playground
by themyth92
HTML
<script src="http://jasmine.github.io/1.3/lib/jasmine.js"></script>
<script src="http://jasmine.github.io/1.3/lib/jasmine-html.js"></script>
<link rel="stylesheet" href="http://jasmine.github.io/1.3/lib/jasmine.css">
<script src="https://code.angularjs.org/1.2.9/angular.js"></script>
<script src="https://code.angularjs.org/1.2.9/angular-mocks.js"></script>
JavaScript
//--- CODE --------------------------
(function (angular) {
// Create module
var myApp = angular.module('app', []);
myApp.controller('LoginController', function LoginController($scope, $http, userService) {
$scope.test = "hello";
$scope.authenticateUser = function () {
var username = 'test';
var password = '123456';
var token = "";
$http.get('http://localhost:8080/services/request').success(function (data) {
$scope.result = data.status;
userService.authenticateUser(username, password, "").then(function (response) {});
});
};
});
myApp.factory('userService', ['$http', function ($http) {
return {
authenticateUser: function (username, password, requestToken) {
var status = $http({
method: 'POST',
url: "http://localhost:8080/services/access",
data: {},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).success(function (data, status, headers, config) {
return data;
}).
error(function (data, status, headers, config) {
return null;
});
return status;
}
}
}]);
})(angular);
// ---SPECS-------------------------
describe('Login controller', function () {
beforeEach(module('app'));
var httpBackend, ctrl, scope, userService;
beforeEach(inject(function ($controller, $rootScope, $httpBackend, $injector, _userService_) {
scope = $rootScope.$new();
httpBackend = $injector.get('$httpBackend');
userService = _userService_;
ctrl = $controller('LoginController', {
$scope: scope
});
}));
it('should set authentication true', function () {
...