glass-app-manager
Version:
Informatica's Glass Framework CLI for bootstrapping
42 lines (36 loc) • 1.28 kB
JavaScript
/**
* A global setup file that binds enzyme into the react ecosystem
* so we can execute all tests with Enzyme if we wish. This file
* is read jest in `package.json` and is executed _once_ before
* all tests run.
* @author Amar Mishra <ammishra@informatica.com>
* @version 1.0.0
*/
// JSDOM configuration copied from https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md
const { JSDOM } = require("jsdom");
const jsdom = new JSDOM("<!doctype html><html><body></body></html>");
const { window } = jsdom;
//initialize windows variables for testing
require("./public/UI_Config.js");
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === "undefined")
.reduce(
(result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop)
}),
{}
);
Object.defineProperties(target, props);
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: "node.js"
};
copyProps(window, global);
const Enzyme = require("enzyme");
const EnzymeAdapter = require("enzyme-adapter-react-16");
// Setup enzyme's react adapter
Enzyme.configure({ adapter: new EnzymeAdapter() });