I'm trying to write some tests for a controller, but ALL the documentation/tutorials/etc on this demonstrate with functions and variables on $scope. What if you want to test something NOT on $scope?
Ex:
app.controller('fakeCtrl', function($scope) {
var foo = 'bar';
function fooBar() {
console.log('foo bar');
}
});
Is there any way to unit test foo
or fooBar()
?
Here's what DOESN'T work:
describe("fake controller", function(){
beforeEach(module('app'));
var $controller;
beforeEach(inject(function(_$controller_, $rootScope){
$controller = _$controller_;
$scope = $rootScope.$new();
}));
describe('foo property', function() {
it('is bar', function() {
var controller = $controller('fakeCtrl', { $scope: $scope });
expect(controller.foo).toEqual('bar');
});
});
...
Aucun commentaire:
Enregistrer un commentaire