Created
July 24, 2014 20:35
-
-
Save scudelletti/a76517a5c88c794cb476 to your computer and use it in GitHub Desktop.
Chai Custom Matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Chai - Add CustomMatchers | |
usage: | |
var CustomMatchers = require('./support/friendly_news_path_matcher'); | |
chai.use(CustomMatchers); | |
expect('/materia/FooBar').to.be.a.friendlyNewsPath(); | |
*/ | |
'use strict'; | |
var CustomMatchers = function sinonChai(chai) { | |
chai.Assertion.addMethod('friendlyNewsPath', function () { | |
var obj = this._obj; | |
var expectedMessage = 'expected #{this} to seems like "/materia/:editorial/:slug"'; | |
var notExpectedMessage = 'expected #{this} to not seems like "/materia/:editorial/:slug"'; | |
var paths = obj.split('/'); | |
var assertion = paths.length === 3 && paths[0] === '' && paths[1] === 'materia' && paths[2].match(/^.{1,}/); | |
this.assert(assertion, expectedMessage, notExpectedMessage, '/materia/:editorial/:slug', obj); | |
}); | |
}; | |
module.exports = CustomMatchers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment