Skip to content

Instantly share code, notes, and snippets.

@scudelletti
Created July 24, 2014 20:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scudelletti/a76517a5c88c794cb476 to your computer and use it in GitHub Desktop.
Save scudelletti/a76517a5c88c794cb476 to your computer and use it in GitHub Desktop.
Chai Custom Matcher
/*
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