在WebStorm中使用supertest会产生“参数types不能分配给参数types”和“未parsing的函数或方法”
我在WebStorm IDE中开发了一个nodejs项目。 我使用摩卡超单元作为我的unit testing框架。
WebStorm显示了两个警告: Argument type app|exports|module.exports is not assignable to parameter type Function|Server
和Unresolved function or method get()
。
我尝试从File -> Settings -> Languages & Frameworks -> JavaScript -> Libraries -> Download
但没有发生任何事情下载和安装supertest库。 所以我直接从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):
启用库: Node.js Core
, ECMAScript 6
, HTML
, HTML5/ECMAScript5
, Jasmine Definitely Typed
。 后者实际上并不是必需的,因为WebStorm可以从Mocha node_modules中parsing' describe()
'等,但是可以避免检查茉莉花东西丢失的导入情况。
似乎你的项目中有一些定义与你的request
定义相冲突。 当您按Ctrl +点击request
时,您采取了哪些代码?
- 在需要的时候,扼杀/嘲笑一个返回函数的库
- 如何检测是否在node.js中运行摩卡testing?
- 节点摩卡testing日志保存到磁盘
- 如何在NodeJs中loggingwebdrivertesting的video
- Supertest定制节点中的服务器
- 在Windows上开发并构build在Linux上的代码上使用NodeJs的Grunt?
- 用jenkins运行量angular器testing抛出“testing`标题”应该是一个“string”,但“function”被给予代替。
- 为所有testing用例(Mocha)添加一个默认的before()函数,
- 摩卡与节点:只显示testing失败的日志logging