Reference Error:在Jest中运行单元测试时未定义KO

发布于 2025-02-04 01:17:34 字数 1100 浏览 3 评论 0原文

我是Jest和Stackoverflow发布的新手。 我一直在尝试添加用于敲除的应用程序的单位测试用例,但是在运行测试时获得参考:ko未定义错误。任何帮助将不胜感激。

以下是package.json文件。

    {
  "name": "jstesting",
  "version": "1.0.0",
  "description": "",
  "main": "eVIPs.js",
  "type": "module",
  "scripts": {
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/preset-react": "^7.17.12",
    "jest": "^28.1.0",
    "jest-html-reporters": "^3.0.8",
    "typescript": "^2.9.2"
  },
  
  "dependencies": {
    "@babel/preset-env": "^7.18.2",
    "@babel/preset-typescript": "^7.17.12",
    "babel-jest": "^28.1.0",
    "jquery": "^3.6.0",
    "knockout": "^3.5.1"
  },
  "jest": {
    "reporters": [
      "default",
      [
        "jest-html-reporters",
        {
          "publicPath": "./html-report",
          "filename": "report.html",
          "openReport": false
        }
      ]
    ],
    "collectCoverage": true
  }
}

这是测试文件。

    import testLogin from '../loginPage';
import homeJS, { HomeViewModel } from '../Home';

I am new to Jest and Stackoverflow posting.
I have been trying to add unit test cases for knockoutJS application but getting ReferenceError: ko is not defined error when running the test. Any help would be appreciated.

below is the package.json file.

    {
  "name": "jstesting",
  "version": "1.0.0",
  "description": "",
  "main": "eVIPs.js",
  "type": "module",
  "scripts": {
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/preset-react": "^7.17.12",
    "jest": "^28.1.0",
    "jest-html-reporters": "^3.0.8",
    "typescript": "^2.9.2"
  },
  
  "dependencies": {
    "@babel/preset-env": "^7.18.2",
    "@babel/preset-typescript": "^7.17.12",
    "babel-jest": "^28.1.0",
    "jquery": "^3.6.0",
    "knockout": "^3.5.1"
  },
  "jest": {
    "reporters": [
      "default",
      [
        "jest-html-reporters",
        {
          "publicPath": "./html-report",
          "filename": "report.html",
          "openReport": false
        }
      ]
    ],
    "collectCoverage": true
  }
}

and this is the test file.

    import testLogin from '../loginPage';
import homeJS, { HomeViewModel } from '../Home';

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文