admin管理员组文章数量:1336434
I'm trying to port my javascript unit tests to typescript, however, a simply test with build in matcher fails:
describe('test getBranches', function() {
it('returns an array of branches', function() {
branchService.getBranches(owner, name)
.then(function(res) {
expect(res).to.exist;//<-- this is where the error is from
})
})
})
The error says:
error TS2339: Property 'to' does not exist on type 'Matchers'.
I'm new to typescript but I guess I'm missing some type files for mocha or chai? I have since installed typings
and did the following:
typings install dt~mocha --save --global
typings install dt~chai --save --global
typings install dt~chai-as-promised --save --global
But it doesn't make a difference at all.
Note that the generated js file is fine, the test passed. I just want to know why typescript is giving this error and how can I make it disappear.
I'm trying to port my javascript unit tests to typescript, however, a simply test with build in matcher fails:
describe('test getBranches', function() {
it('returns an array of branches', function() {
branchService.getBranches(owner, name)
.then(function(res) {
expect(res).to.exist;//<-- this is where the error is from
})
})
})
The error says:
error TS2339: Property 'to' does not exist on type 'Matchers'.
I'm new to typescript but I guess I'm missing some type files for mocha or chai? I have since installed typings
and did the following:
typings install dt~mocha --save --global
typings install dt~chai --save --global
typings install dt~chai-as-promised --save --global
But it doesn't make a difference at all.
Note that the generated js file is fine, the test passed. I just want to know why typescript is giving this error and how can I make it disappear.
Share Improve this question edited Nov 3, 2016 at 16:49 swang asked Nov 3, 2016 at 16:29 swangswang 5,2595 gold badges36 silver badges58 bronze badges 5-
Where does
Matchers
e from? I doesn't look like it a part ofchai
. Also how do you importexpect
? – martin Commented Nov 3, 2016 at 16:47 - @Martin, the error is from line expect(res).to, so I assume expect returns a Matcher type? – swang Commented Nov 3, 2016 at 16:49
-
1
Yes, I'm asking where does
Matchers
class e from because it doesn't exist in neithermocha
github./mochajs/mocha/search?utf8=%E2%9C%93&q=Matchers norchai
github./chaijs/chai/search?utf8=%E2%9C%93&q=Matchers so it looks like you have something wrong with your imports. – martin Commented Nov 3, 2016 at 16:56 - 1 @Martin, you are right, I found Matchers from jasmine-expect, does it mean I'm using jasmine rather than chai? How do i make typescript pick chai's expect? I'm not importing anything in my ts files – swang Commented Nov 3, 2016 at 17:09
-
Have a look in your
typings.d.ts
maybe you left something there. – martin Commented Nov 3, 2016 at 17:12
1 Answer
Reset to default 3Ideally install both mocha
and chai
via @types
scope as npm package:
npm install --save @types/mocha
npm install --save @types/chai
npm install --save @types/chai-as-promised
This way you can abandon typings
tool pletely even with including all /// <reference path=....
directives.
For more info see: https://blogs.msdn.microsoft./typescript/2016/06/15/the-future-of-declaration-files/
本文标签:
版权声明:本文标题:javascript - Typescript throw error Property 'to' does not exist on type 'Matchers' when compili 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315687a2451770.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论