Anyone know how to make custom plugins work with IDE hinting/completion?

29 views
Skip to first unread message

Bryce Carr

unread,
Apr 15, 2020, 1:47:05 AM4/15/20
to Chai.js
Hello friends,

I've made a couple of chai plugins for use at work: https://gist.github.com/bdcarr/1216b0d639420bcd9c98c894bbd60048

They work like such:
// See if one of the payreturns has a property called PayRule, which equals overtimeRuleId
// also takes a single PayReturn object if you wanna
expect
(arrayOfPayreturns).to.have.payrule(overtimeRuleId, "custom failure message")

// See if the object has a property called Value, with a value of 30
expect
(payreturn).to.have.Value(30, "custom failure message")

Pretty straightforward, but I don't use them too often and always have to go back and check what the expected arguments are. Even if I did have a better memory, I wouldn't want to inflict this experience on anyone who uses my library in future. The inbuilt chai assertions don't have this issue, because my IDE (jetbrains webstorm/intellij) recognises their signature and gives me a lovely little tooltip like so:

tooltip.png


Hitting 'go to definition' on the inbuilt 'equals' assertion takes me to a typescript file, index.d.ts, which I guess is where webstorm gets the signature from. But I can't figure out how it works, and am not sure what terms I should google in order to learn. Would anyone be able to point me in the right direction?


Cheers!
Reply all
Reply to author
Forward
0 new messages