mercredi 28 janvier 2015

How to inject factory into unit test

I am trying to inject my factory into my unit test.


I have something in my file like



//inside my 'testCtrl' I have

$scope.getProduct = function() {
//other codes..
myFactory.getProduct()
.then(function(obj){
$scope.product.id = obj.id;
})
}


my factory file



angular.module('myApp').factory('myFactory', function($http, $q) {
//codes...
})


my test file.



describe('unit test here', function(){
beforeEach(module('myApp'));
beforeEach(module('myFactory'));
beofreEach(inject(function(_$controller_, _$rootscope_) {
scope._$rootScope.$new();

testCtrl = _$controller_('testCtrl', {
$scope:scope
})
})

//I got a Module 'plannerFactory' is not available error
//How do I inject myFactory into my test file here and how do I //use it?

})


I have been searching on the web and couldn't find any useful info. Could anyone help me about it? Thanks a lot!


Aucun commentaire:

Enregistrer un commentaire