Skip to content

Instantly share code, notes, and snippets.

@jrr
Created November 10, 2016 02:43
Show Gist options
  • Save jrr/12b3089ec1d830efbb177c522e8f40ea to your computer and use it in GitHub Desktop.
Save jrr/12b3089ec1d830efbb177c522e8f40ea to your computer and use it in GitHub Desktop.
custom qunit assertions
import QUnit from 'qunit';
QUnit.assert.contains = function( haystack, needle, message ) {
var result = haystack.indexOf(needle) > -1;
this.pushResult( {
result: result,
actual: haystack,
expected: needle,
message: message || `'${haystack}' contains string '${needle}'`
});
};
QUnit.assert.matches = function( haystack, needle, message ) {
var result = needle.test(haystack);
this.pushResult( {
result: result,
actual: haystack,
expected: needle.toString(),
message: message || `'${haystack}' matches regex ${needle}`
});
};
QUnit.assert.gt = function( a, b, message ) {
this.pushResult( {
result: a > b,
actual: a,
expected: `> ${b}`,
message: message || `${a} > ${b}`
});
};
QUnit.assert.hasClass = function( a, b, message ) {
this.pushResult( {
result: a.hasClass(b),
actual: a.attr('class') || '',
expected: b,
message: message || `${a.prop('nodeName')} has class '${b}''`
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment