Created
January 21, 2020 07:49
-
-
Save hypery2k/19ee1aa8ea2967d47b87eac4317af0c2 to your computer and use it in GitHub Desktop.
Jest Web Components Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'jest-preset-angular'; | |
import 'mutationobserver-shim'; | |
// Mock environment | |
var mockedRegistry = new Map(); | |
var win = <any>window; | |
win.alert = () => {}; | |
win.customElements = { | |
define: (elementName, elementClass) => {}, | |
get: tagName => mockedRegistry.get(tagName) | |
}; | |
// mock XHR | |
// e.g. for api/config/keycloak | |
const xhrMockClass = () => ({ | |
open: jest.fn(), | |
abort: jest.fn(), | |
send: jest.fn(), | |
setRequestHeader: jest.fn(), | |
addEventListener: jest.fn(), | |
removeEventListener: jest.fn() | |
}); | |
win.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment