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

Problem with loading Karma test runner #51

Closed
bolshchikov opened this issue Apr 16, 2014 · 4 comments
Closed

Problem with loading Karma test runner #51

bolshchikov opened this issue Apr 16, 2014 · 4 comments

Comments

@bolshchikov
Copy link

The following code works fine in the browser with AMD but doesn't work in Karma test runner:

define(['pubsub'], function (pubsub) {
  pubsub.publish('test');
});

In Karma, pubsub is undefined, because it takes the route of common js thinking that module is defined

// CommonJS
if (typeof exports === 'object' && typeof module !== 'undefined'){
    module.exports = factory();

// AMD
} else if (typeof define === 'function' && define.amd){
    define(factory);
// Browser
} else {
    root.PubSub = factory();
}
@mroderick
Copy link
Owner

I guess it would be preferable to test for the AMD case first, as is done in https://github.com/umdjs/umd/blob/master/returnExports.js

@bolshchikov
Copy link
Author

@mroderick, so I assume this solution will also resolve the issue #49

@mroderick
Copy link
Owner

How does the code not work in the Karma test runner?
Do they define both exports and module globals?

Did you try modifying PubSubJS to use the UMD pattern linked above?

@mroderick
Copy link
Owner

This has been fixed with #63, and is included in 1.5.0

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