I've been using Yeoman to setup projects, and was trying to build an angular module project that would apply feature toggles. I'm getting hung up with Jasmine testing at the unit level, here is one of my tests:
var scope, Rules;
var elm;
// load the controller's module
beforeEach(function() {
module('featureToggle.directives', function($provide) {
$provide.decorator('Rules', function($delegate) {
$delegate.resolveByName = jasmine.createSpy();
return $delegate;
});
});
inject(function(_Rules_) {
Rules = _Rules_;
});
});
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
elm = angular.element(
'<h1 feature-toggle feature-name="hello">' +
'Hello World' +
'</h1>');
scope = $rootScope;
$compile(elm)(scope);
scope.$digest();
}));
it('should render the content when the feature is enabled', function() {
jasmine.spyOn(Rules, 'resolveByName').andReturn(false);
var contents = elm.find('h1');
expect(contents.eq(0)).toHaveClass('hidden');
});
I'm getting an odd failure.
TypeError: 'undefined' is not a function (evaluating 'jasmine.spyOn(Rules, 'resolveByName')')
The karma.conf is very vanilla.
frameworks = ['jasmine'];
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'app/components/angular/angular.js',
'app/components/angular-mocks/angular-mocks.js',
'src/*.js',
'src/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
];
I'm using PhantomJS by and large, but the same issue exists (with a different dialect of the same error) in Chrome.
Using $log, nothing is actually undefined. So I'm rather lost.
Change jasmine.spyOn() to just spyOn().
Btw, not sure why you are spying the same method twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With