fix nthchild false negative #1757

merged 2 commits into from Nov 16, 2015


None yet

2 participants

mstrutt commented Nov 14, 2015

Passing a function in to Modernizr.addTest resulted the code being executed after elem had been removed from the DOM (and so had no layout). I've moved the code to be executed immediately and the just the result (which I renamed just to make the last line a bit more human readable) passed into Modernizr.addTest.

I searched the rest of the css feature-detects and nthchild appears to be the only test with this issue. That said, might be worth adding a little note to the docs about time of execution with testStyles and addTest.

All tests passed locally before and after this fix, but it was a bit beyond me to dive into what's happening with them

fixes #1675

@mstrutt mstrutt fix nthchild false negative
@ryanseddon ryanseddon commented on an outdated diff Nov 15, 2015
@@ -27,15 +27,12 @@ define(['Modernizr', 'testStyles'], function(Modernizr, testStyles) {
// A Javascript loop then tests if the `<div>`s have the expected width
// using the modulus operator.
testStyles('#modernizr div {width:1px} #modernizr div:nth-child(2n) {width:2px;}', function(elem) {
- Modernizr.addTest('nthchild', function() {
- var elems = elem.getElementsByTagName('div'),
- test = true;
+ var elems = elem.getElementsByTagName('div'),
+ correctWidths = true;
ryanseddon Nov 15, 2015 Member

Can you change this to multiple var's this is an old one but all other tests should use this pattern going forward

@mstrutt mstrutt separating var declarations
mstrutt commented Nov 15, 2015

done :)

@ryanseddon ryanseddon merged commit b42ce72 into Modernizr:master Nov 16, 2015

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed

Thanks @mstrutt

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