Issue running tests when include ant components
See original GitHub issuePls, 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:
- Created 7 years ago
- Comments:14 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t appear to be fixed with the latest antd version
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