Skip to content

Commit

Permalink
fixed some unit tests and added a test for attribute selector support…
Browse files Browse the repository at this point in the history
… in IE7+
  • Loading branch information
scottjehl committed Jan 16, 2012
1 parent b652928 commit e8f2678
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/unit/index.html
Expand Up @@ -22,7 +22,7 @@ <h2 id="qunit-userAgent"></h2>
<div id="launcher"></div> <div id="launcher"></div>


<!-- elem for applying css via queries --> <!-- elem for applying css via queries -->
<div id="testelem"></div> <div id="testelem" class="foo">test</div>


</body> </body>
</html> </html>
4 changes: 4 additions & 0 deletions test/unit/test.css
Expand Up @@ -13,13 +13,17 @@


#testelem { #testelem {
width: 50px; width: 50px;
display: block;
} }


/*styles for 480px and up */ /*styles for 480px and up */
@media screen and (min-width: 480px) { @media screen and (min-width: 480px) {
#testelem { #testelem {
width: 150px; width: 150px;
} }
#testelem[class=foo] {
height: 200px;
}
} }


/*styles for 500px and under*/ /*styles for 500px and under*/
Expand Down
34 changes: 32 additions & 2 deletions test/unit/tests.js
Expand Up @@ -27,6 +27,23 @@ window.onload = function(){
function heightApplied( val ){ function heightApplied( val ){
return testElem.offsetHeight === val; return testElem.offsetHeight === val;
} }

// A short snippet for detecting versions of IE in JavaScript - author: @padolsey
var ie = (function(){

var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');

while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);

return v > 4 ? v : undef;

}());


window.moveTo(0,0); window.moveTo(0,0);


Expand All @@ -40,13 +57,25 @@ window.onload = function(){
}); });


asyncTest( 'styles within min-width media queries apply properly', function() { asyncTest( 'styles within min-width media queries apply properly', function() {
window.resizeTo(500,600); window.resizeTo(520,600);
setTimeout(function(){ setTimeout(function(){
ok( widthApplied( 150 ), 'testelem is 150px wide when window is 500px wide' ); ok( widthApplied( 150 ), 'testelem is 150px wide when window is 500px wide' );
start(); start();
}, 900); }, 900);
}); });


// This test is for a feature in IE7 and up
if( ie >= 7 ){
asyncTest( "attribute selectors still work (where supported) after respond runs its course", function() {
window.resizeTo(520,600);
setTimeout(function(){
ok( heightApplied( 200 ), "testelem is 200px tall when window is 500px wide" );
start();
}, 900);
});
}


asyncTest( 'styles within max-width media queries apply properly', function() { asyncTest( 'styles within max-width media queries apply properly', function() {
window.resizeTo(300,600); window.resizeTo(300,600);
setTimeout(function(){ setTimeout(function(){
Expand Down Expand Up @@ -78,7 +107,7 @@ window.onload = function(){
asyncTest( "Styles within a false media query do not apply", function() { asyncTest( "Styles within a false media query do not apply", function() {
window.resizeTo(800,600); window.resizeTo(800,600);
setTimeout(function(){ setTimeout(function(){
ok( !widthApplied( 500 ), "testelem is not 500px wide when window is 1300px wide" ); ok( !widthApplied( 500 ), "testelem is not 500px wide when window is 800px wide" );
start(); start();


}, 900); }, 900);
Expand All @@ -92,6 +121,7 @@ window.onload = function(){
}, 900); }, 900);
}); });



} }


}; };

0 comments on commit e8f2678

Please sign in to comment.