【问题标题】:Using should.js how to check whether a string is not present in an array?使用 should.js 如何检查数组中是否不存在字符串?
【发布时间】:2017-05-10 16:13:00
【问题描述】:

想检查一个字符串是否存在于我们做someArray.should.contain('str')的数组中,但我找不到这个的否定大小写检查。

【问题讨论】:

  • Trott 的回答似乎是正确的。虽然我对should.js 不是很熟悉,但根据documentation,似乎.not 可以在任何地方使用,据我所知。
  • 是的,它“应该”是正确的,但不知道为什么不能让它工作,给TypeError: undefined is not a functionshould.not.
  • someArray.should.contain('str') -> true 如果 'str' 出现在 someArray 中。否则为假。对吗?
  • 是的@Seram 就是这样
  • 那你为什么需要另一个函数呢?我只是好奇。

标签: javascript mocha.js should.js


【解决方案1】:

使用.not 应该可以:someArray.should.not.contain('str')

should.js README 没有提到.contain()。因此,如果简单地插入 .not 不起作用,请使用 .containEql()

【讨论】:

  • should.js 文档没有提到contain。也许有一些与 mocha 混合和匹配,而您真正想要的是 containEql 或类似的东西?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-18
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多