Skip to content

Instantly share code, notes, and snippets.

@fpirsch
Created September 30, 2014 14:02
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 fpirsch/1790c604a6d54d372a40 to your computer and use it in GitHub Desktop.
Save fpirsch/1790c604a6d54d372a40 to your computer and use it in GitHub Desktop.
Protractor/jasmine toHaveClass custom matcher
/**
* Custom "toHaveClass" matcher.
*
* Based on https://gist.github.com/darthwade/9305669
* and https://gist.github.com/elgalu/94284ec0ac3e8a590507
*
* usage :
* require('./toHaveClass.js');
* ...
* expect($('html')).toHaveClass('wf-active');
* expect($('#button')).not.toHaveClass('disabled');
*/
/* global beforeEach, protractor */
beforeEach(function() {
this.addMatchers({
toHaveClass: function (expected) {
var deferred = protractor.promise.defer();
this.actual.getAttribute('class').then(function(classes) {
var hasClass = classes.split(' ').indexOf(expected) >= 0;
deferred.fulfill(hasClass);
});
return deferred.promise;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment