Я пытался заставить JSDOM работать в моих модульных тестах машинописного текста, но после многих попыток я продолжал получать следующую ошибку (или варианты следующей ошибки)
TypeError: _jsdom.JSDOM is not a constructor
Фрагмент кода это следующее
import React from 'react';
import { act } from 'react-dom/test-utils';
import { expect } from 'chai';
import { mock, instance, verify, anyOfClass } from 'ts-mockito';
import { JSDOM } from 'jsdom'
import { TestApp } from '../ts/ExampleForTestingReact';
let rootContainer: HTMLDivElement;
const { window } = new JSDOM('<!doctype html><html><body></body></html>');
Мой пакет json следующий
{
"name": "app",
"version": "1.0.0",
"private": true,
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/preset-env": "^7.9.0",
"@babel/preset-react": "^7.10.1",
"@babel/preset-typescript": "^7.9.0",
"@babel/register": "^7.9.0",
"@types/bootstrap": "4.3.2",
"@types/chai": "^4.2.0",
"@types/mocha": "^7.0.2",
"@types/react": "^16.9.31",
"@types/react-dom": "^16.9.6",
"@types/jsdom": "^16.2.3",
"babel-loader": "^8.1.0",
"chai": "^4.2.0",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.6.0",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.3.0",
"image-webpack-loader": "^6.0.0",
"mini-css-extract-plugin": "^0.9.0",
"mocha": "^7.1.1",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"terser-webpack-plugin": "^3.0.6",
"ts-loader": "^7.0.5",
"ts-mockito": "^2.5.0",
"ts-node": "^8.8.1",
"typescript": "3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"jsdom-global": "^3.0.2"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.13.1",
"bootstrap": "^4.3.1",
"bootstrap-table": "^1.16.0",
"file-saver": "^2.0.2",
"jquery": "^3.3.1",
"jquery-validation": "^1.17.0",
"jquery-validation-unobtrusive": "^3.2.11",
"moment": "^2.26.0",
"mpx-dialog": "^1.1.12",
"mpx-error-boundary": "^1.0.0",
"mpx-multi-language": "^1.0.8",
"mpx-react-page-components": "^1.0.3",
"mpx-utilities": "^1.0.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"tableexport.jquery.plugin": "^1.10.20"
},
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
},
"mocha": {
"extension": [
"ts",
"tsx"
],
"spec": "wwwroot/ts-tests/**/*.test.tsx",
"require": "wwwroot/ts-tests/babel-register.js"
},
"scripts": {
"test": "mocha",
"pack-dev": "webpack --mode development",
"pack-prod": "webpack --mode production",
"clean": "del /Q /F .\\wwwroot\\dist\\*.*"
}
}
Я пытался сделать следующее: { ссылка }
Любая помощь по этому поводу будет принята с благодарностью!