Last active
August 29, 2015 14:03
-
-
Save yeehaa123/570b6882d24e7447e20d to your computer and use it in GitHub Desktop.
problem with $httpBackend
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
| (function(){ | |
| 'use strict'; | |
| angular.module('cth').factory('Post', ['$http', '$q', Post]); | |
| function Post($http, $q){ | |
| function getAll(){ | |
| return $http.get('/api/posts.json').then(function(response){ | |
| return response.data.posts; | |
| }); | |
| } | |
| return { | |
| getAll: getAll | |
| }; | |
| } | |
| })(); |
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 'Post', -> | |
| beforeEach(module('cth')) | |
| describe 'api calls', -> | |
| beforeEach inject ($injector) -> | |
| @service = $injector.get('Post') | |
| @$httpBackend = $injector.get('$httpBackend') | |
| it "makes an ajax call to '/api/posts.json'", -> | |
| @$httpBackend.expectGET('/api/posts.json').respond({msg: "hello"}) | |
| @service.getAll().then (data)-> | |
| console.log(data) | |
| @$httpBackend.flush() |
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 'Post', -> | |
| beforeEach(module('cth')) | |
| describe 'api calls', -> | |
| beforeEach inject ($injector) -> | |
| @service = $injector.get('Post') | |
| @$httpBackend = $injector.get('$httpBackend') | |
| it "makes an ajax call to '/api/posts.json'", -> | |
| posts = {} | |
| @$httpBackend.whenGET('/api/posts.json').respond({msg: "hello"}) | |
| @service.getAll().then (data)-> | |
| posts = data | |
| @$httpBackend.flush() | |
| expect(posts.msg).toBe("Hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment