Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automated CSS Testing: Not just a myth

Jakob Mattsson
September 10, 2013

Automated CSS Testing: Not just a myth

Presented at MMWCON 2013, UCLA, Los Angeles

Jakob Mattsson

September 10, 2013
Tweet

More Decks by Jakob Mattsson

Other Decks in Programming

Transcript

  1. Declarative programming is a programming paradigm that expresses the logic

    of a computation without describing its control flow.” “
  2. New styles are added instead of reuse Unused styles are

    not removed No overview of how different styles interact
  3. New styles are added instead of reuse Unused styles are

    not removed No overview of how different styles interact Form factors, adaptiveness, responsiveness
  4. New styles are added instead of reuse Unused styles are

    not removed No overview of how different styles interact Form factors, adaptiveness, responsiveness The true ”write-only” language
  5. In computer humor, a write-only language is a programming language

    with syntax (or semantics) sufficiently dense and bizarre that any routine of significant size is too difficult to understand by other programmers and cannot be safely edited.” “
  6. 1

  7. Syntax Checks Checking that the code is actually valid CSS

    Typically performed by an editor, IDE or plugin
  8. 2

  9. Styleguides & linting Forces best-practices to be followed Syntactically (where

    to put braces) Semantically (catching common mistakes)
  10. Useless without good rules + - Prevents anti-patterns Easy to

    apply Doesn’t test the end result - - +
  11. 3

  12. Lots of false positives + - No change can sneak

    by Implementation agnostic Breaks on content changes - - +
  13. 4

  14. Comparing styles in the DOM Sniff the DOM for all

    relevant styles Compare them to some expectation
  15. Style rules != looks + - Resilient to changes Tests

    live on Writing expectations in code - - +
  16. My suggestion: 1. Create the design you want 2. Ensure

    consistency and compatibility 3. Eliminate redundancy
  17. My suggestion: 1. Create the design you want 2. Ensure

    consistency and compatibility 3. Eliminate redundancy
  18. My suggestion: 1. Create the design you want 2. Ensure

    consistency and compatibility 3. Eliminate redundancy
  19. My suggestion: 1. Create the design you want 2. Ensure

    consistency and compatibility 3. Eliminate redundancy
  20. ul:last-child { color: red; } Won’t work in IE8. Will

    be caught when test runs there. #footer { width: calc(100% - 3em); } Won’t work on Android or Safari < 6 Unsupported CSS-style used
  21. CSS-inconsistency across browsers <html> <head> <style type="text/css"> h1, h2, h3,

    h4, h5, h6, a { display: block; } ul { list-style-position: inside; } </style> </head> <body> <ul> <li> <h3>Foobar</h3> </li> <ul> </body> </html> Chrome Firefox
  22. <html> <head> <style type="text/css"> body { margin:0; padding:0; } div

    { margin:0; padding:10; } </style> </head> <body> <div>Foobar</div> </body> </html> <html> <head> <style type="text/css"> body { margin:10; padding:0; } div { margin:0; padding:0; } </style> </head> <body> <div>Foobar</div> </body> </html> Detecting equivalent styles This change does not trigger an error; the rendered result is the same, even though styles differ.
  23. Automated CSS Testing Not Just a Myth @jakobmattsson • [email protected]

    github.com/leanmachine/testbit bit.ly/jakob-mmwcon + -