Skip to content

Commit

Permalink
fix(configs): fix tests using popper.js
Browse files Browse the repository at this point in the history
Mocks document.createRange which is used by popper.js, dependency of react-popper.
  • Loading branch information
connor-baer committed Nov 9, 2019
1 parent d88e4db commit 541cd60
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/* global expect */

import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import '@testing-library/jest-dom/extend-expect';
Expand Down Expand Up @@ -59,6 +61,18 @@ global.__DEV__ = false;
global.__PRODUCTION__ = false;
global.__TEST__ = true;

// react-popper relies on document.createRange
if (global.document) {
document.createRange = () => ({
setStart: () => {},
setEnd: () => {},
commonAncestorContainer: {
nodeName: 'BODY',
ownerDocument: document
}
});
}

// Add custom matchers
expect.extend(toHaveNoViolations);

Expand Down

0 comments on commit 541cd60

Please sign in to comment.