Skip to content

Instantly share code, notes, and snippets.

@seamusleahy
Created June 28, 2017 15:04
Show Gist options
  • Save seamusleahy/2b27ee1ac8590224dbf2c31592f3e4da to your computer and use it in GitHub Desktop.
Save seamusleahy/2b27ee1ac8590224dbf2c31592f3e4da to your computer and use it in GitHub Desktop.
How to fix the Enzym warning when mounting to component to the body
$ npm test
> example@1.0.0 test /home/user/project
> jest
PASS src/__tests__/WithErrorExample.test.jsx
Example
✓ Test (108ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.032s
Ran all test suites matching "Example".
console.error node_modules/fbjs/lib/warning.js:36
Warning: render(): Rendering components directly into document.body is discouraged, since its children are often manipulated by third-party scripts and browser extensions. This may lead to subtle reconciliation issues. Try rendering into a container element created for your app.
import React from 'react';
import { mount } from 'enzyme';
import Example from '../Example';
describe('Example', () => {
it('Test', () => {
const alertDialog = mount(<Example />, { attachTo: document.body });
expect(true).toEqual(true);
});
});
import React from 'react';
import { mount } from 'enzyme';
import Example from '../Example';
describe('Example', () => {
it('Test', () => {
const holder = document.createElement('div');
document.body.appendChild(holder);
const alertDialog = mount(<Example />, { attachTo: holder });
expect(true).toEqual(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment