Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.
Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.
Install cross-env:
| import routeHandler from '../src/routeHandler'; | |
| import { mockResponse, mockRequest } from './test-helpers'; | |
| jest.mock('@googlemaps/google-maps-services-js'); | |
| import { Client } from '@googlemaps/google-maps-services-js'; | |
| const mockClient = { | |
| geocode: jest.fn(), | |
| }; |
| // Modified version of this Stack Overflow response: | |
| // https://stackoverflow.com/a/48459005/1950503 | |
| // (Removes ramda dependency, adds .trim() to string replacer, adds it to Jest global var instead of exporting) | |
| // To use: | |
| // Put `<rootDir>/path/to/customWhitespaceMatcher.js` in your Jest config under setupFiles | |
| // Call it in your tests like this: | |
| // expect( | |
| // customMatchers.whitespaceMatcher(receivedResult, expectedResult).pass | |
| // ).toBeTruthy(); |
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <div><button id="button" type="submit" disabled><span>Go</span></button></div> | |
| <pre id="log"></pre> | |
| <script> | |
| function logEventCapturing(event) { document.getElementById('log').textContent += `${event.type} on ${this.localName} capturing path:${event.composedPath().length}\n`; } | |
| function logEventBubbling(event) { document.getElementById('log').textContent += `${event.type} on ${this.localName} bubbling path:${event.composedPath().length}\n`; } |
| var devices = [ | |
| { name: 'Desktop - Huge', width: 2880, height: 1800, ratio: 2, type: 'desktop' }, | |
| { name: 'Desktop - Extra Large', width: 1920, height: 1080, ratio: 1, type: 'desktop' }, | |
| { name: 'Desktop - Large', width: 1440, height: 900, ratio: 1, type: 'desktop' }, | |
| { name: 'Desktop - HiDPI', width: 1366, height: 768, ratio: 1, type: 'desktop' }, | |
| { name: 'Desktop - MDPI', width: 1280, height: 800, ratio: 1, type: 'desktop' }, | |
| { name: 'Laptop with HiDPI screen', width: 1440, height: 900, ratio: 2, type: 'desktop' }, | |
| { name: 'Laptop with MDPI screen', width: 1280, height: 800, ratio: 1, type: 'desktop' }, | |
| { name: 'Laptop with touch', width: 1280, height: 950, ratio: 1, type: 'desktop' }, | |
| { name: 'Tablet - Portrait', width: 768, height: 1024, ratio: 1, type: 'tablet' }, |