question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue running tests when include ant components

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
eranimocommented, May 2, 2017

This doesn’t appear to be fixed with the latest antd version

6reactions
kushnirocommented, Jan 22, 2017

to save some people time in the future: it seems to be solved inside antd by adding a polyfill before the react-slick import but babel moves it after the requires in the compiled code in the npm package. see: https://github.com/babel/babel/issues/2061

so to get around this you can is ‘require’ instead of ‘import’ for your component in your test code.

any ideas for a better solution? @afc163 @benjycui

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Tests in a Deployment | Ant Migration Tool Guide
If any test fails, the entire deployment is rolled back. If the deployment includes components for the following metadata types, all local tests...
Read more >
React test - Ant Design Pro
This test will mount the component, and then test whether it throws errors. It only requires very little coding to bring great benefits....
Read more >
Ant + JUnit = ClassNotFoundExceptions when running tests?
If I don't include the jars in the classpath, I get errors telling me that junit.jar must be on the classpath in order...
Read more >
JUnit Task - Apache Ant
withOutAndErr is the same as on but also includes the output of the test as written to System.out and System.err . No; default...
Read more >
Main Components of Apache ANT Task Parameters - Provar
provar:run or Run-Test-Case: The Runner task executes your test cases and produces an execution report in HTML format. (Refer to the Provar Runner...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found