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

Running in headless tests produces "Error: matchMedia not present" #82

Closed
binarykitchen opened this issue Oct 13, 2013 · 3 comments
Closed

Comments

@binarykitchen
Copy link

Hi again

When I run my app with enquire.js in an automated headless test unit like https://github.com/assaf/zombie then following error is produced and is polluting my console:

Error: matchMedia not present, legacy browsers require a polyfill
    at Object.MediaQueryDispatch (<anonymous>:226:19)
    at <anonymous>:291:12
    at <anonymous>:15:37
    at Object.context.execCb (<anonymous>:1635:33)
    at Object.Module.check (<anonymous>:866:55)
    at Object.Module.enable (<anonymous>:1142:22)
    at Object.Module.init (<anonymous>:779:26)
    at callGetModule (<anonymous>:1169:63)
    at Object.context.completeLoad (<anonymous>:1529:21)
    at Object.context.onScriptLoad (<anonymous>:1656:29)

Not sure what a solution would be. Probably a new option would be good.

@WickyNilliams
Copy link
Owner

I guess the problem is that Zombie omits the matchMedia API. Reading through the docs it seems that this is the case.

What are you trying to test: Your code using enquire? Or something else, where enquire is incidental? If the latter you could easily stub out the matchMedia API:

window.matchMedia = window.matchMedia || function() {
    return {
        matches : false,
        addListener : function() {},
        removeListener: function() {}
    };
};

If the former, then you have to do a proper polyfill. Presumably this is possible with zombie (since it explicitly omits a lot of APIs, I assume there must be some way to do it)?

@binarykitchen
Copy link
Author

Thx man. Stubbing out that API is a good idea. With this my Zombie tests won't crash anymore.

@hellqvist
Copy link

Hi, I know that this is closed but I can't get it to work.

I've tried stubbing matchMedia both inside the test file and in a separate file link in under jest in package.json.

The result is always that matchMedia is undefined in enquire.js

What am I missing?

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

3 participants