Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active August 29, 2015 14:14
Show Gist options
  • Save ajcrites/8a4398e5ce907bace946 to your computer and use it in GitHub Desktop.
Save ajcrites/8a4398e5ce907bace946 to your computer and use it in GitHub Desktop.
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);
});
});
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