I think it would be possible in the browser (client-side) to "unit test" CSS. It would be more like an automated checker than an unit testing:
- Evaluate the final CSS attribute conditions we would like to preserve for a particular CSS class or ID (the result).
- We require a testing document HTML to render the static content and CSS. All elements should be included in the content in separate containers.
Unit testing case:
This should always be the final attributes:
A function to set test rules in JS could be:
addCSSUnitTest(".test1, .test2, #test3", "margin-left: 4px; font-size: 8px");
Then we check if DOM elements have this final attributes.
Also you should always have a reset.css for cross-browser "compatibility".