Created
September 30, 2014 14:02
-
-
Save fpirsch/1790c604a6d54d372a40 to your computer and use it in GitHub Desktop.
Protractor/jasmine toHaveClass custom matcher
This file contains hidden or 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
/** | |
* 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