繁体   English   中英

希农和埃斯林特

[英]Sinon and eslint

我正在与Karma,Jasmine和Sinon一起为我的角度应用程序编写单元测试,并且在我的代码库中运行eslint。

我定义了将在beforeEach inject使用的全局变量,以创建sinon.stub ESLint一直抱怨我的全局变量已定义但从未使用过。 例如:

'getListStub' is defined but never used no-unused-vars

但是在我的代码中看起来像这样

var listService, getListStub;

beforeEach(inject(function(_listService_) {
  listService = _listService_;
  getListStub = sinon.stub(listService, 'getList').returns(q.when(listResponse));
}

阻止ESLint产生错误的最佳方法是什么?

在这些测试文件的顶部设置/*eslint no-unused-vars: 0*/最好吗?

如果您不在任何地方使用getListStub ,为什么要将其分配给变量?

JS闭包和内存管理的属性(特别是保留引用的对象)将使您可以直接使用_listService_ ,并且不需要缓存getListStub

如果那在sinon上正常工作,您应该可以将函数重写为:

beforeEach(inject(function(_listService_) {
  sinon.stub(_listService_, 'getList').returns(q.when(listResponse));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM