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

MatchMedia error when run own tests #40

Open
Danjavia opened this issue Oct 5, 2016 · 2 comments
Open

MatchMedia error when run own tests #40

Danjavia opened this issue Oct 5, 2016 · 2 comments

Comments

@Danjavia
Copy link

Danjavia commented Oct 5, 2016

Pls, can you helpme?

Your project includes the enquirejs dependency. But I have issues when try to run tests into my project because

matchMedia not present, legacy browsers require a polyfill

I don't know how to solve this issue.

this is my code

import React from 'react';
import { shallow } from 'enzyme';
import { expect } from 'chai';

// Import components for testing here
import NavbarCrm from '../NavbarCrmComponent';

describe('<NavbarCrm />', function () {

  if (typeof window !== 'undefined') {
    var matchMediaPolyfill = function matchMediaPolyfill(mediaQuery) {
      return {
        media: mediaQuery,
        matches: false,
        addListener: function addListener() {},
        removeListener: function removeListener() {}
      };
    };
    window.matchMedia = window.matchMedia || matchMediaPolyfill;
  }

  it('should have props for heading and children', function (done) {
    const wrapper = shallow(<Menu />);
    expect(wrapper.props().classes).to.be.defined;
    expect(wrapper.props().children).to.be.defined;
    done();
  });
});

I tried in all methods. Above, below but the same error ever.

Can U help me?

I cant to solve the issue putting

if (typeof window !== 'undefined') {
    var matchMediaPolyfill = function matchMediaPolyfill(mediaQuery) {
      return {
        media: mediaQuery,
        matches: false,
        addListener: function addListener() {},
        removeListener: function removeListener() {}
      };
    };
    window.matchMedia = window.matchMedia || matchMediaPolyfill;
  }

I include the above code in the line 49826 located at andt.js file into my node_modules And the problem is over. but this is not a good solution.

into enquirejs/src/include/wrap.js into the dist file for npm installed module. But it isn't a pretty solution.

@xcatliu
Copy link
Owner

xcatliu commented Oct 19, 2016

Have you tried to include

if (typeof window !== 'undefined') {
    var matchMediaPolyfill = function matchMediaPolyfill(mediaQuery) {
      return {
        media: mediaQuery,
        matches: false,
        addListener: function addListener() {},
        removeListener: function removeListener() {}
      };
    };
    window.matchMedia = window.matchMedia || matchMediaPolyfill;
  }
}

in the beginning of your entry JavaScript file?

@Danjavia
Copy link
Author

Yes, I Do, but not work! :(

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