如何通过调用scope
Restangular service
的控制器
//services.js
/* QOD Service */
app.service('QODService',
['QODAPI',
function (QODAPI) {
return QODAPI
}
]
);
//controllers.js
app.controller('QODController',
['$scope', 'QODService',
function ($scope, QODService) {
$scope.qod = null;
QODService.one().get().then(
function (response) {
$scope.qod = response.qod['quote'];
},function (error) {}
)
}
]
);
// test.js
'use strict';
describe('QOD', function () {
var $httpBackend, QODController, response, scope = {}, QODService;
beforeEach(module('app'));
beforeEach(inject(function($controller, _$httpBackend_, _QODService_){
$httpBackend = _$httpBackend_;
QODService = _QODService_;
response = {
"qod": {
"quote": 'Winning is nice if you don\'t lose your integrity in the process.',
"author": "Arnold Horshak"
}
};
$httpBackend.whenGET('/v1/qod/').respond(response);
QODController = $controller('QODController', {
$scope: scope, QODService: QODService
});
}));
describe('QODController', function () {
it('Should be defined', function() {
expect(QODController).toBeDefined();
});
it('Should return QOD', function() {
// Returns null ??? How do I check the response
console.log(scope);
});
});
});