Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to instantiate module function fakeRouteProvider #7

Closed
bbohling opened this issue Jun 10, 2015 · 8 comments
Closed

Failed to instantiate module function fakeRouteProvider #7

bbohling opened this issue Jun 10, 2015 · 8 comments

Comments

@bbohling
Copy link

Sounds similar to some other closed issues, but no solution jumped out at me. Using 0.1.3 of bardjs I am getting the following error:

Error: [$injector:modulerr] Failed to instantiate module function fakeRouteProvider($provide) due to:
    TypeError: 'undefined' is not a function (evaluating 'sinon.stub()')
        at /Users/bbohling/Projects/itdz/itdz-ui/app/bower_components/bardjs/dist/bard.js:377

My spec is a complete rip off of something John Papa did in one of his Pluralsight trainings:

describe('itdz', function() {
    var controller;
    var page = mockPage.getPage();

    beforeEach(function() {
        bard.appModule('itdz');
        bard.inject('$controller', '$q', '$rootScope', 'pageService');
    });

    beforeEach(function() {
        sinon.stub(pageService, 'slug').returns($q.when(page));
        controller = $controller('Content');
        $rootScope.$apply();
    });

    bard.verifyNoOutstandingHttpRequests();

    describe('Content controller', function() {
        it('should be created successfully', function () {
            expect(controller).to.be.defined;
        });

        describe('after activate', function() {
            it('should have called pageService.slug 1 time', function () {
                expect(pageService.slug).to.have.been.calledOnce;
            });

        });
    });
});

And I verified that sinon is indeed included in the karma files array. Any ideas what I am doing wrong? I am assuming it's my fault. :)

@wardbell
Copy link
Owner

Put a breakpoint at the top and check to see if sinon exists. If it doesn't, you're doing something wrong.

Expecting karma framework config to be something like this:

frameworks: ['mocha', 'chai', 'sinon', 'chai-sinon'],

Shouldn't be in karma config files section. Maybe that is the problem.

Look again at the bardjs readme. If it isn't clear enough, please make a suggested improvement in a PR.

@bbohling
Copy link
Author

Yep, I have the frameworks setup identically to what is in the readme. Though I had to add karma-sinon (and karma-chai-sinon) via npm...otherwise it would give me an error.

Sinon is undefined though so definitely not being injected somehow. Yours and John's Play by Play was great, but I'm ready for the entire Testing (deep dive) training series John keeps threatening. ;-)

@bbohling
Copy link
Author

Actually I was wrong, sinon is an object when I set a breakpoint at the top of the spec.

@bbohling
Copy link
Author

Thanks to this article I found the issue. I needed to change my sinon bower dependency to point to the release file. Seems a bit odd that one would need to do that, but it seems to have fixed the issue. Now onto the next issue. :)

@wardbell
Copy link
Owner

How can we give the appropriate guidance in the bardjs readme? Propose something. I take PRs :-)

@bbohling
Copy link
Author

Since I'm a newbie in this space I would first like to verify that my implementation is required, then I can absolutely do a PR. Can you verify that your reference to sinon in your bower.json file looks like:

"sinon": "http://sinonjs.org/releases/sinon-1.9.0.js"

rather than:

"sinon": "^1.14.1",

I'm guessing the other variable at play here is how we put together our tests (i.e., karma.config.js) via Grunt, Gulp or similar.

@wardbell
Copy link
Owner

Actually I just updated (v.0.1.4) the sinon to the most recent version by request (see issue #8 ).

sinon": "http://sinonjs.org/releases/sinon-1.15.0.js"

And, yes, I have to do it this way because there is no official bower package for sinon

Someone is trying to maintain a sinon bower package independently (sinonjs) ... I believe that is the package to which you refer. But his is not "official" and it's several releases behind right now. I'm tempted but am not quite comfortable ... yet.

@wardbell
Copy link
Owner

wardbell commented Jul 1, 2015

Closing because I have not heard from you and have no reason to believe there is a problem for me to fix. Happy to reopen if you think I should

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants