问题
Ive been using John Papa's style guide for my angular apps and Im just starting to get into the testing.
However I can't seem to find any good documentation regarding testing the style with mocha, chai, and jasmine.
Here is an example of one of my controllers
(function () {
'use strict';
angular.module('app').controller('appController', appControllerFunction);
function appControllerFunction($scope, $rootScope, $location, dataService, dataFactory) {
var vm = this;
function getData()
{
vm.data = dataService.returnData().then(function(data){
... //http service returning data
});
...
}
getData();
where my service and factory are in different folders and files following the .spec.js format.
I've been trying to test the controller and factories using mocha, chai, and jasmine and can't seem to get any passing tests.
Here is my test for the controller:
'use strict';
describe('Controller: appController', function(){
var scope, controller, rootScope, location, dataService, dataFactory;
beforeEach(module('app'));
beforeEach(inject(function($controller, $rootScope, _$location_, dataService, dataFactory ) {
rootScope = $rootScope;
controller = $controller;
scope = $rootScope.$new();
location = _$location_;
dataService = dataService;
dataFactory = dataFactory
var controller = $controller('appController', {
$scope: scope,
$location: location,
dataFactory: dataFactory
dataService: dataService
});
scope.$digest();
}));
it('should be defined', inject(function(dataFactory){
expect(dataFactory).toBeDefined();
}));
});
Thanks for your input and help!
来源:https://stackoverflow.com/questions/31620332/how-to-test-john-papa-vm-model-controllers-and-factories-unit-testing-with-jasmi