Last active
August 29, 2015 14:14
-
-
Save ajcrites/8a4398e5ce907bace946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Home', function () { | |
var HomeCtrl, $httpBackend; | |
beforeEach(angular.mock.module('app')); | |
beforeEach(angular.mock.inject(function ($controller, _$httpBackend_) { | |
$httpBackend = _$httpBackend_; | |
$httpBackend.when("GET", "/things.json") | |
.respond([4,5,6]); | |
HomeCtrl = $controller("HomeCtrl"); | |
})); | |
it("should have the first thing", function () { | |
$httpBackend.flush(); | |
expect(HomeCtrl.thing).toBe(4); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app', []) | |
.factory('thing', function ($http) { | |
var things = []; | |
return { | |
getThings: function () { | |
return things; | |
}, | |
fetchThings: function () { | |
return $http.get("/things.json").success(function (serverThings) { | |
things = serverThings; | |
}); | |
}, | |
}; | |
}) | |
.controller('HomeCtrl', function (thing) { | |
var home = this; | |
thing.fetchThings().success(function () { | |
home.thing = thing.getThings()[0]; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment