How to test John papa vm.model controllers and factories unit testing with jasmine?

梦想与她 提交于 2020-01-14 02:08:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!