Like to check whether a string is present in an array we do someArray.should.contain('str')
, but I can't find the negation case check for this.
Asked
Active
Viewed 2,998 times
2

Koustuv Sinha
- 1,640
- 19
- 34
-
Trott's answer appears to be correct. While I'm not very familiar with `should.js`, according to the [documentation](https://github.com/tj/should.js#not), it seems `.not` can be used anywhere, so far as I can tell. – Paul Richter Apr 24 '15 at 15:37
-
yes it "should" be correct, but don't know why cant get it to work, giving `TypeError: undefined is not a function` at `should.not.` – Koustuv Sinha Apr 24 '15 at 15:40
-
someArray.should.contain('str') -> true if 'str' present in someArray. Otherwise false. right? – Yellen Apr 24 '15 at 15:43
-
yes @Seram that is the case – Koustuv Sinha Apr 24 '15 at 15:44
-
Then why do you need another function? I'm just curious. – Yellen Apr 24 '15 at 15:46
-
no actually the thing is I need to check the presence of a certain string in an array in one check, and the absence of the same string in the next check. thus I need the not condition – Koustuv Sinha Apr 24 '15 at 15:48
1 Answers
7
Using .not
should work: someArray.should.not.contain('str')
The should.js
README does not mention .contain()
. So if simply inserting .not
does not work, use .containEql()
.
-
5`should.js` docs don't mention `contain`. Maybe there's some mixing and matching going on with mocha and what you really want is `containEql` or something like that? – Trott Apr 24 '15 at 15:39