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

Karma not executing my tests with require #606

Closed
TKTheTechie opened this issue Jun 27, 2013 · 4 comments
Closed

Karma not executing my tests with require #606

TKTheTechie opened this issue Jun 27, 2013 · 4 comments

Comments

@TKTheTechie
Copy link

Hi,
I've begun writing tests for my app and for some reason, karma refuses to execute them. I know for sure that the tests are loaded because when I make a syntax error, karma reports it but it doesn't fail/pass the tests that I specified.

'use strict';
require(['angular', 'app'], function (angular, myApp) {
    beforeEach(angular.module('myApp'));
    describe('angular test', function () {
        it('works for angular', function () {
            // just checking that angular works
            var mccModule = angular.module('myApp');
            expect(mccModule).to.equal(null); //should fail but doesn't

        });
    });

    describe('subjectmodel sevice test', function () {
        it('should contain a subjectmodel service', inject(function (subjectModel) {
            expect(subjectModel).not.to.equal(null);
        }));
    });

});

Karma gives the following output -
PhantomJS 1.9 (Windows) LOG: '/base/test/webapp/unit/myTest.js'
PhantomJS 1.9 (Windows): Executed 0 of 0 SUCCESS (1.175 secs / 0 secs)

The log statement is from my test-main.js

for (var file in window.__karma__.files) {
    if (/Test\.js$/.test(file)) {
        tests.push(file);
        console.log(file);
    }
}
@vojtajina
Copy link
Contributor

What is your config file look like ?
Can you open http://localhost:9876/debug.html and check out the web inspector console ? Is there any error ?

@vojtajina
Copy link
Contributor

Closing this, as I assume it's duplicate of #600 - if you have any more questions, you can ask on mailing list groups.google.com/forum/?fromgroups#!forum/karma-users

@TKTheTechie
Copy link
Author

Hi Vojta,

No it wasn't a duplicate. I figured it out and it seems that all tests need to use define(...) instead of require(...) otherwise they won't run. I still don't quite understand why... could you explain?

@vojtajina
Copy link
Contributor

See
http://stackoverflow.com/questions/9507606/when-to-use-require-and-when-to-use-define

I think when you use "require" you can't load that file as a dependency,
which is what you need to do in your test-main.js

If you used "require" you would have to include these files directly (not
ask require.js to load them), however then, you don't know, when require is
done with loading these files (and its deps) and therefore you don't know,
when to start the test run (if you start jasmine/mocha before require
finished loading, jasmine will ignore the tests that are not loaded yet, as
they get registered too late).

On Sun, Jun 30, 2013 at 6:15 AM, PocketDealHunter
notifications@github.comwrote:

Hi Vojta,

No it wasn't a duplicate. I figured it out and it seems that all tests
need to use define(...) instead of require(...) otherwise they won't run. I
still don't quite understand why... could you explain?


Reply to this email directly or view it on GitHubhttps://github.com//issues/606#issuecomment-20246979
.

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