Bob
Bob

Reputation: 10795

jasmine spy on jquery

I have a jQuery function:

$.fn.Header = function (options) {
    return this.each(function () {
        // bla bla
    });
};

And somewhere in my code I call it:

function initHeader() {
    // some code before

    $('my-header').Header({

    });
}

And I have a jasmine test:

it('shows header in some cases', function () {
    var Header = spyOn($.fn, 'Header');
    expect(Header).toHaveBeenCalledWith('Header');
});

When running a test I get following error:

TypeError: 'undefined' is not a function (evaluating '$('my-header').Header')
    at initHeader
    .....
    Header() method does not exist

What is the problem and how I can fix it?

P.S. I have added jQuery to karma.conf.js file.

Upvotes: 1

Views: 167

Answers (1)

aarjithn
aarjithn

Reputation: 1181

This doesn't look like a jasmine error as it is thrown from code. Seems it is not able to find your Header method. Check if the js file with $.fn.Header definition is included as well in karma config.

Upvotes: 1

Related Questions