Skip to content

Instantly share code, notes, and snippets.

@AndersDJohnson
Last active June 5, 2019 13:34
Show Gist options
  • Select an option

  • Save AndersDJohnson/4274664 to your computer and use it in GitHub Desktop.

Select an option

Save AndersDJohnson/4274664 to your computer and use it in GitHub Desktop.
chai plugins
((plugin) ->
# Module systems magic dance.
if (typeof require == "function" && typeof exports == "object" && typeof module == "object")
# NodeJS
module.exports = plugin
else if (typeof define == "function" && define.amd)
# AMD
define -> plugin
else
# Other environment (usually <script> tag): plug in to global chai instance directly.
chai.use plugin
)(
(chai, utils) ->
utils.addMethod(chai.assert, 'notInclude', ((haystack, needle) ->
chai.assert(
typeof haystack.indexOf is 'function' and haystack.length?
'expected first parameter to be an Array or String, but it wasn\'t'
'expected first parameter to be an Array or String, and it was'
)
chai.assert(
haystack.indexOf(needle) is -1
'expected [' + haystack + '] not to include ' + needle + ', but it did'
'expected [' + haystack + '] not to include ' + needle + ', and it didn\'t'
)
))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment