node.js - 在WebStorm中使用supertest产生 'Argument type is not assignable to parameter type'和 'Unresolved function or method'

标签 node.js express mocha.js webstorm supertest

我有一个在WebStorm IDE中开发的nodejs项目。我使用 Mocha 和 supertest 作为我的单元测试框架。

WebStorm 显示了 2 个警告:参数类型 app|exports|module.exports 无法分配给参数类型 Function|Server未解析的函数或方法 get()

我尝试从文件 -> 设置 -> 语言和框架 -> JavaScript -> 库 -> 下载下载并安装 super 测试库,但没有任何反应。所以我直接从https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/supertest下载了它们并手动添加它们,但 WebStorm 仍然产生相同的警告。

这是我的 server.js 代码:

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.status(200).end();
});

app.listen(3000);

module.exports = app;

这是我的 servertest.js 代码:

/* eslint-env mocha*/

const request = require('supertest');
const app = require('../server');

describe('GET /', () => {
  it('should respond OK', (done) => {
    request(app) //Argument type app|exports|module.exports is not 
                 //assignable to parameter type Function|Server
        .get('/') //Unresolved function or method
        .expect(200, done);
  });
});

如何消除这些警告?

最佳答案

对我来说效果很好(WebStorm 2016.2):

enter image description here

启用的库:Node.js CoreECMAScript 6HTMLHTML5/ECMAScript5 Jasmine 绝对打字。后者实际上并不是必需的,因为 WebStorm 可以解析 Mocha node_modules 中的“describe()”等,但可以避免检查有关 jasmine 内容缺失导入的情况。

您的项目中似乎有一些定义与您的请求定义相冲突。当您按住 Ctrl 键并单击请求时,您会看到什么代码?

关于node.js - 在WebStorm中使用supertest产生 'Argument type is not assignable to parameter type'和 'Unresolved function or method',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38303966/

相关文章:

html - 通过 app.post 呈现的页面出现 `Confirm Form Resubmission` 问题( '/' ,在expressjs中

javascript - 未处理的 Promise 拒绝警告 : TypeError: First argument must be a string or Buffer

javascript - Postman 中是否有一个功能可以在所有其他功能之前只运行一次测试

azure - 当前正在此存储帐户上执行需要独占访问的操作

javascript - 手动安装 Node js 与使用包管理器安装

node.js - Tibco EMS 协议(protocol)

postgresql - Node postgres : Setting max connection pool size

node.js - node.js、express 和 EJS 的 WebStorm 代码补全

node.js - Flutter:在图像中存储字节

node.js - Passport Facebook : how to dynamically set callbackURL?