Skip to content

Instantly share code, notes, and snippets.

@toolness
Created August 16, 2012 02:14
Show Gist options
  • Save toolness/3365671 to your computer and use it in GitHub Desktop.
Save toolness/3365671 to your computer and use it in GitHub Desktop.
CSS testing script for refactorings
(function(jQuery) {
var $ = jQuery;
function test(name, selectors, css) {
console.log("CSS test: " + name);
selectors.forEach(function(selector) {
var passed = 0;
var elements = $(selector);
if (!elements.length)
return console.error(" FAIL - nothing matches " + selector);
elements.each(function() {
var $el = $(this);
for (var property in css) {
var value = $el.css(property);
if (!value.match(css[property]))
return console.error(" FAIL - " + selector + " " + property +
" is " + value + ", not " + css[property]);
}
passed++;
});
if (elements.length == passed)
console.log(" OK - " + selector + " (" + passed + ")");
});
}
test("font is Ubuntu Mono", [
".CodeMirror", ".CodeMirror-lines", ".CodeMirror textarea",
".CodeMirror-gutter-text", ".cm-s-jsbin span.cm-comment"
], {
'font-family': /Ubuntu Mono/
});
})(jQuery);
@toolness
Copy link
Author

I used this script to test my refactorings in toolness/friendlycode@1da86b8.

@toolness
Copy link
Author

Example output:

CSS test: font is Ubuntu Mono
 OK - .CodeMirror (1)
 OK - .CodeMirror-lines (1)
 OK - .CodeMirror textarea (1)
 OK - .CodeMirror-gutter-text (1)
 FAIL - nothing matches .cm-s-jsbin span.cm-comment
 FAIL - html font-family is Times, not /Ubuntu Mono/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment