在纯JavaScript nodejs中开玩笑typeError

时间:2018-10-31 14:31:43

标签: javascript testing jestjs

我无法使其正常运行,并且正在寻求帮助。 问题如下:每当我用--watchAll开玩笑时,都会导致此错误:

TypeError: Cannot read property 'Object.<anonymous>' of null
        at Runtime._execModule (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/jest-runtime/build/index.js:447:72)
        at Runtime.requireModule (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/jest-runtime/build/index.js:265:14)
        at Runtime.requireModuleOrMock (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/jest-runtime/build/index.js:337:19)
        at Object.factory (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/mathjs/lib/function/arithmetic/divide.js:6:27)
        at load (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/mathjs/lib/core/core.js:106:28)
        at resolver (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/mathjs/lib/core/function/import.js:220:24)
        at Object.get [as divide] (/home/timmy/react/yogist/yogist_chatbot_server/node_modules/mathjs/lib/utils/object.js:210:20)
        at getScoreMatrix (/home/timmy/react/yogist/yogist_chatbot_server/controllers/recommendation_engine.js:38:29)
        at /home/timmy/react/yogist/yogist_chatbot_server/controllers/chatbot.js:110:61
        at <anonymous>

我发现它在以下任何一种情况下都会消失: 删除我的

matrix = mathjs.divide(matrix, mathjs.norm(matrix, "fro"));

在我的代码中排行。

OR

在玩笑测试中添加一个具有大约200ms延迟的setTimeout

OR

在没有watchALL或watch标志的情况下开玩笑。

当我运行npx jest时也会出现。 (因此没有观看标志)

仅当使用笑话进行测试时,它才会出现,代码可以无缝运行(它也可以处理此错误,测试成功)。

这似乎是相关的:5205,但我无法正确理解解决方案。有人可以再解释一下吗?

这是开玩笑的测试代码:

import request from "supertest";
import Server from "../index";
import path from "path";
import _ from "lodash";

const chai = require("chai");
const expect = chai.expect;

const API_BASE_PATH = "localhost:3000/";

describe("testing userActions", () => {
  beforeAll(done => {
    setTimeout(() => {
      done();
    }, 1);
  });
  afterAll(() => {
    Server.close();
  });
  describe("GET user/getSubscription", () => {
    it("should return 200 OK.", done => {
      return request(Server)
        .post(API_BASE_PATH + "user/getSubscription")
        .send({
          headers: {
            authorization: ""
          }
        })
        .end((err, res) => {
          console.log("this is the error:", res.data);
          if (!err && res.body) {
            console.log("values are:", res.body);
            done("");
          } else {
            done(err);
          }
        });
    });
  });
});

这是我package.json的相关部分:

...    "dependencies": {
        "babel-cli": "^6.26.0",
        "babel-core": "^6.26.0",
        "babel-jest": "^23.0.6",
        "babel-loader": "^7.1.4",
        "babel-preset-es2015": "^6.24.1",
        "bcrypt-nodejs": "^0.0.3",
        "body-parser": "^1.18.2",
        "config": "^1.30.0",
        "cors": "^2.8.4",
        "express": "^4.16.3",
        "fs": "^0.0.1-security",
        "hash.js": "^1.1.5",
        "jquery-csv": "^0.8.9",
        "jwt-simple": "^0.5.1",
        "kuker-emitters": "^6.7.4",
        "lodash": "^4.17.10",
        "mathjs": "^5.2.3",
        "moment": "^2.22.1",
        "mongoose": "^5.0.10",
        "mongoose-moment": "^0.1.3",
        "mongoose-type-url": "^1.0.2",
        "morgan": "^1.9.0",
        "node-schedule": "^1.3.0",
        "nodemailer": "^4.6.4",
        "nodemon": "^1.17.2",
        "npx": "^10.2.0",
        "passport": "^0.4.0",
        "passport-jwt": "^4.0.0",
        "passport-local": "^1.0.0",
        "path": "^0.12.7",
        "random-token": "^0.0.8",
        "require": "^2.4.20",
        "socket.io": "^2.0.4",
        "socket.io-redis": "^5.2.0",
        "stent": "^5.1.0",
        "stripe": "^6.1.0",
        "uuid": "^3.2.1",
        "winston": "^3.0.0"
      },
      "devDependencies": {
        "chai": "^4.1.2",
        "jest": "^23.6.0",
        "jest-cli": "^22.0.4",
        "supertest": "^3.0.0",
        "webpack": "^4.23.1",
        "webpack-cli": "^3.1.2",
        "webpack-node-externals": "^1.7.2"
      }, ...

0 个答案:

没有答案