The problem I'm trying to solve is the ability to test my factory with Jasmine.
Below is a copy of my application and factory:
var app = angular.module('app', []); app.factory('service', function ($http) { return { getCustomers: function (callback) { $http.get('/Home/Customers').success(callback); }, getProfile: function (callback, viewModel) { $http.post('/Home/Profiles', JSON.stringify(viewModel), { headers: { 'Content-Type': 'application/json' } }).success(callback); } }; });
:::::::::::::::::::::::::
I also have jasmine installed, but I am having problems testing the above getCustomers and getProfile.
Below is my current attempt:
describe("getCustomers", function (service) { beforeEach(module('service')); describe('getCustomers', function () { it("should return a list of customers", inject(function(getCustomers){ expect(getCustomers.results).toEqual(["david", "James", "Sam"]); })) }) });
This would be very useful if someone could provide an example of how to test "getCustomers" and "getProfile" in two separate tests.
Sincerely.
source share