node.js - 引用错误: describe is not defined

标签 node.js testing mocha.js

我正在尝试使用 gest 运行 graphql 端点测试。下面是我的代码

const Gest = require('graphicli')
const schema = require('./path/schema.js')

const gest = Gest(schema, {
  baseURL: 'http://localhost:7770/graphql',
  headers: {
    Accept: 'application/json'
  }
})

describe('GraphQL', () => {
  test('{getAllNominator{firstName}}', () => {
    return gest('{getAllNominator{firstName}}').then(({ data, errors }) => {
      expect(errors).toBeUndefined()
      expect(data).toEqual('Adam')
    })
  })
})

但是我收到以下错误

ReferenceError: describe is not defined

根据Solution Link给出的解决方案我使用mocha运行该文件。但它给出了另一个错误

ReferenceError: test is not defined

我被困在这里了。我该如何解决这个问题。还有一个问题。 gest Mocha 有关系吗? 请有人帮我解决这个问题

最佳答案

describe 函数由 mocha 设置。

如果您已在本地安装了 mocha,请使用

运行测试
./node_modules/.bin/mocha path/to/test.js

或者

mocha path/to/test.js

此外,您可能希望将 test(...) 调用替换为 it(...)

关于node.js - 引用错误: describe is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46193653/

相关文章:

测试 BPEL 流程?

javascript - POST 请求中的测试和 stub 参数

node.js - Babel 无法使用 Mocha 并启动 Node 服务器

node.js - 更新 Node 模块不会影响程序

node.js - 强制关闭 node.js http 服务器中的所有连接

javascript - 谷歌分析即时测试器

javascript - 如何使用 chai 或 mocha 检查图像是否存在?

Node.js Mongoosejs Crud 脚手架

node.js - 首先使用Node和pg创建数据库后如何创建表

jsf - 如何在我的 JSF 项目中进行 Selenium 测试?