React how to test in conjunction typescript + mocha + enzyme?

Hi. Maybe someone can share with me the starter kit or boilerplate for such testing? By itself, the mocha is configured quite easily, but typescripts somehow everything becomes sad... then the importing of modules is offered, the mode --watch in Moka falls off...

In obshem I would be grateful for any advice. On svaki case, here's what I nacpil:
// package.json

"test": "mocha-w-r ts-node/register-r babel-register.js -r ignore-styles -r setup.js src/tests/*.spec.tsx",


// babel-register.js

require("@babel/polyfill");
require("@babel/register")({
 ignore: [
/node_modules\/(?!(ol)\/)/
],

 presets : ["react-app","@babel/preset-typescript"],
 plugins : [
"inline-react-svg",
"@babel/preset-typescript"
],
 extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".tsx"],
 cache: false,
 });


// babel-config
module.exports = function (api) {
 //we will keep here all the supplementary babel options
 api.cache(false); 
 return {
 "env": {
 "test" : {
 "compact": false
}
}
}
};


// setup.js
const { JSDOM } = require('jsdom');

const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
 const props = Object.getOwnPropertyNames(src)
 .filter(prop => typeof target[prop] === 'undefined')
 .reduce((result, prop) => ({
...result
 [prop] is Object.getOwnPropertyDescriptor(src, prop)
 }), {});
 Object.defineProperties(target, props);
}

global.window = window;
global.document = window.document;
global.window.requestAnimationFrame = (cb) => {
 return setTimeout(cb, 0);
};
global.window.cancelAnimationFrame = (cb) => {
 return setTimeout(cb, 0);
}
global.navigator = {
 userAgent: 'node.js',
};
copyProps(window, global);
March 23rd 20 at 19:47
0 answer

Find more questions by tags ReactJavaScript