Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Tests via CSS #86

Open
aleemb opened this issue Aug 5, 2015 · 2 comments
Open

UI Tests via CSS #86

aleemb opened this issue Aug 5, 2015 · 2 comments

Comments

@aleemb
Copy link

aleemb commented Aug 5, 2015

I am not sure if this is common practise or not but some of our developers ended up creating .grid__item without a .grid or incorrect nesting. I came up with an idea for a system for catching these through a test stylesheet along the lines of:

/* grid__item should always be within a grid */
.grid__item {
    outline: 5px solid red;
}
.grid > .grid__item {
    outline: none;
}

/* grid should only have grid__item as children */
.grid > :not(.grid__item) {
    outline: 5px solid red;
}

I am pretty sure this idea can be extended to other rules to allow developers to visually validate markup. It helped me catch a bunch of errors, especially when markup is being dynamically generated, nested or refactored.

What do you think?

@aleemb aleemb changed the title UI Unit Tests UI Tests via CSS Aug 5, 2015
@unwiredbrain
Copy link

Interesting idea. I'd move it to a debug version though (something like csswizardry-grids.debug.scss) so not to mess up with the production version.

@aleemb
Copy link
Author

aleemb commented Aug 5, 2015

@unwiredbrain yeah this should not make it's way into production for obvious reasons lest your users see red lines.

Building on the general idea, if you wanted, you could styles such as :after { content:'fail', display: 'none'; } and then write a JS stub. The JS stub could notify you via console.log or even send HTTP requests to example.com/css-errors so you can automatically collect CSS bugs in the wild. That would be pretty sweet actually. Not proposing that for CSS Wizardry, but more of a cool trick for automated CSS testing.

EDIT: Posted here https://medium.com/@aleemb/ui-unit-tests-via-css-automatically-catch-errors-in-your-code-in-production-6f75826ec170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants