-
Notifications
You must be signed in to change notification settings - Fork 222
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
support jest / react-test-renderer #225
Comments
It can't – it's rendering an actual modal into a portal, and as such needs real access to the DOM. |
have you reconsidered this at all? Are there any potential workarounds coming in the future? |
For the moment I've been mocking portals in the top of the test file like this: jest.mock('rc-util/lib/Portal') Obviously you'll need to install the |
@reyronald this lib does not seems to use |
Folks what taion is saying is that it's actually impossible to do this because of how portals work. The alternative is we make it "work" by rendering nothing, which isn't helpful for testing either. I'd use renderIntoDocument, enzymes mount(), or test the modal body of your component unwrapped from the modal itself.all these approaches work great |
@thomasbertet It doesn't, you would add it as a dependency in your consuming application when you want to test the modals, not here. |
I got a Modal rendered in Jest test environment by overwriting
The DOM is different in production but that shouldn't matter if e.g. tests just compare snapshots. Is there an immediate problem that I'm missing, rendering Portal's children in place? |
@ArnoSaine -- thank you for that -- your solution worked for me. For anyone else using it, that doesn't want to use lodash, here is my adopted version // jest.setup.js
import {Modal, Portal} from 'react-overlays';
Portal.prototype.render = function render() {
return this.props.children;
};
const originalGetDialogElement = Modal.prototype.getDialogElement;
Modal.prototype.getDialogElement = function() {
const element = originalGetDialogElement.apply(this);
return {
...element,
focus: () => {},
hasAttribute: () => true,
setAttribute: () => {}
}
}; |
This Modal component does not seem support Jest / react-test-renderer.
Simple test:
Returns error:
Currently using the following:
The text was updated successfully, but these errors were encountered: