mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-28 12:55:48 +08:00
@@ -877,8 +877,8 @@ describe("resource", function() {
|
||||
expect(user).toEqualData([ {id: 1, name: 'user1'} ]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', function(){
|
||||
|
||||
describe('get', function(){
|
||||
it('should add them to the id', function() {
|
||||
$httpBackend.expect('GET', '/users/1.json').respond({id: 1, name: 'user1'});
|
||||
var UserService = $resource('/users/:user_id.json', {user_id: '@id'});
|
||||
@@ -908,7 +908,7 @@ describe("resource", function() {
|
||||
var UserService = $resource('/users/:user_id', {user_id: '@id'}, {
|
||||
get: {
|
||||
method: 'GET',
|
||||
url: '/users/:user_id.json'
|
||||
url: '/users/:user_id.json'
|
||||
}
|
||||
});
|
||||
var user = UserService.get({user_id: 1});
|
||||
@@ -1036,13 +1036,13 @@ describe("resource", function() {
|
||||
|
||||
describe('resource', function() {
|
||||
var $httpBackend, $resource;
|
||||
|
||||
|
||||
beforeEach(module(function($exceptionHandlerProvider) {
|
||||
$exceptionHandlerProvider.mode('log');
|
||||
}));
|
||||
|
||||
|
||||
beforeEach(module('ngResource'));
|
||||
|
||||
|
||||
beforeEach(inject(function($injector) {
|
||||
$httpBackend = $injector.get('$httpBackend');
|
||||
$resource = $injector.get('$resource');
|
||||
@@ -1054,14 +1054,16 @@ describe('resource', function() {
|
||||
var failureSpy = jasmine.createSpy('failureSpy');
|
||||
|
||||
$httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'});
|
||||
|
||||
|
||||
$resource('/Customer/123').query()
|
||||
.$promise.then(successSpy, function(e) { failureSpy(e.message); });
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(successSpy).not.toHaveBeenCalled();
|
||||
expect(failureSpy).toHaveBeenCalledWith(
|
||||
'[$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object');
|
||||
expect(failureSpy).toHaveBeenCalled();
|
||||
expect(failureSpy.mostRecentCall.args[0]).toMatch(
|
||||
/^\[\$resource:badcfg\] Error in resource configuration\. Expected response to contain an array but got an object/
|
||||
);
|
||||
});
|
||||
|
||||
it('should fail if action expects an array but response is an object', function() {
|
||||
@@ -1069,14 +1071,16 @@ describe('resource', function() {
|
||||
var failureSpy = jasmine.createSpy('failureSpy');
|
||||
|
||||
$httpBackend.expect('GET', '/Customer/123').respond([1,2,3]);
|
||||
|
||||
|
||||
$resource('/Customer/123').get()
|
||||
.$promise.then(successSpy, function(e) { failureSpy(e.message); });
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(successSpy).not.toHaveBeenCalled();
|
||||
expect(failureSpy).toHaveBeenCalledWith(
|
||||
'[$resource:badcfg] Error in resource configuration. Expected response to contain an object but got an array');
|
||||
expect(failureSpy).toHaveBeenCalled();
|
||||
expect(failureSpy.mostRecentCall.args[0]).toMatch(
|
||||
/^\[\$resource:badcfg\] Error in resource configuration. Expected response to contain an object but got an array/
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user