Skip to content

Commit

Permalink
various test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkettner committed Mar 5, 2015
1 parent 523bc33 commit 3b0e142
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 31 deletions.
2 changes: 1 addition & 1 deletion feature-detects/unicode-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
define(['Modernizr', 'testStyles', 'createElement'], function (Modernizr, testStyles, createElement) {
Modernizr.addTest('unicoderange', function () {

return Modernizr.testStyles('@font-face{font-family:"unicodeRange";src:local("Arial");unicode-range:U+002E}#modernizr span{font-size:10px;display:inline-block;font-family:"unicodeRange",monospace}#modernizr .mono{font-family:monospace}', function (elem) {
return Modernizr.testStyles('@font-face{font-family:"unicodeRange";src:local("Arial");unicode-range:U+0020,U+002E}#modernizr span{font-size:10px;display:inline-block;font-family:"unicodeRange",monospace}#modernizr .mono{font-family:monospace}', function (elem) {

// we use specify a unicode-range of 002E (the `.` glyph,
// and a monospace font as the fallback. If the first of
Expand Down
16 changes: 14 additions & 2 deletions test/browser/integration/caniuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ window.caniusecb = function(caniuse) {
flexboxtweener: 'flexbox',
flexboxlegacy: 'flexbox',
fontface: 'fontface',
formvalidation: 'form-validation',
formvalidationapi: 'form-validation',
fullscreen: 'fullscreen',
gamepads: 'gamepad',
geolocation: 'geolocation',
Expand Down Expand Up @@ -150,14 +150,26 @@ window.caniusecb = function(caniuse) {
o.result = o.result.valueOf();
}

// webgl `partial` support means that not all users with these browsers
// have WebGL access, so we just ignore this test, and only check if the browser
// either fully supports or does not support
if (o.feature === 'webgl' && o.caniuseResult.indexOf('a') === 0) {
return;
}

// change the *documented* false positives
if (!ciubool && (o.feature == 'textshadow' && o.browser == 'firefox' && o.version == 3)) {
ciubool = o.fp = true;
}

// caniuse bundles viewport units, all of which work in IE 9+, save for vmax
// we skip this comparison with a version gate, hoping its fixed in later versions.
if (o.feature === 'cssvmaxunit' && o.browser == 'IE' && o.version < 12) {
if (o.feature === 'cssvmaxunit' && o.caniuseResult.indexOf('a') === 0) {
return;
}

// safari 7 recognizes the `seamless` attribute but does not actually support it
if (o.feature === 'seamless' && o.browser === 'Safari' && o.version === 7) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions test/browser/src/atRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ describe('atRule', function() {
expect(atRule('charset')).to.be('@charset');
});

it('returns false when a property is not given', function() {
expect(atRule()).to.be(false);
});

it('returns false when a property is not found', function() {
expect(atRule('fart')).to.be(false);
});
Expand Down
6 changes: 6 additions & 0 deletions test/browser/src/hasEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ describe('hasEvent', function() {
expect(hasEvent).to.equal(isEventSupported);
});

if (ModernizrProto.hasEvent === hasEvent) {
it('is added to ModernizrProto', function() {
expect(hasEvent).to.equal(ModernizrProto.hasEvent);
});
} else {
it('is added to ModernizrProto', function() {
expect(hasEvent).to.equal(ModernizrProto);
});
}

after(function() {
cleanup();
Expand Down
17 changes: 17 additions & 0 deletions test/browser/src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ describe('load', function() {

}

if (!window.console) {
describe('browsers without a console', function() {

it('doesn\'t blow up when calling console.error', function() {
expect(ModernizrProto.load).to.not.throwError();
});

it('doesn\'t blow up when calling console.warn', function() {
var yepnope = sinon.spy();
window.yepnope = yepnope;
expect(ModernizrProto.load).to.not.throwError();
expect(yepnope.calledOnce).to.be(true);
});

});
}

after(function() {
cleanup();
});
Expand Down
18 changes: 18 additions & 0 deletions test/browser/src/setClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ describe('setClasses', function() {
});
});

describe('cssClasses disabled', function() {
before(function(done) {
setup(done, {
'classPrefix': 'fake',
'enableClasses': false
});
});

it('should not add anything', function(done) {
requirejs(['setClasses'], function(setClasses) {
setClasses(['detect']);
expect(elm.className).to.not.contain('fakedetect');
done();
});
});

after(teardown);
});

describe('cssClasses enabled, with prefix', function() {
before(function(done) {
Expand Down
42 changes: 17 additions & 25 deletions test/browser/src/testMediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,32 @@ describe('testMediaQuery', function() {
expect(testMediaQuery('only fake rule')).to.equal(media('only fake rule').matches);
});
});
}
} else {
describe('fallback version', function() {

describe('fallback version', function() {
var msMMOriginal = window.msMatchMedia;
var mmOriginal = window.matchMedia;
before(function(done) {
injectElementWithStyles = sinon.spy(injectElementWithStyles);
requirejs.undef('injectElementWithStyles');
requirejs.undef('testMediaQuery');

before(function(done) {
injectElementWithStyles = sinon.spy(injectElementWithStyles);
requirejs.undef('injectElementWithStyles');
requirejs.undef('testMediaQuery');
define('injectElementWithStyles', [], function() {return injectElementWithStyles;});

window.msMatchMedia = undefined;
window.matchMedia = undefined;
requirejs(['testMediaQuery'], function(_testMediaQuery) {
testMediaQuery = _testMediaQuery;
done();
});
});

define('injectElementWithStyles', [], function() {return injectElementWithStyles;});
it('works', function() {

requirejs(['testMediaQuery'], function(_testMediaQuery) {
testMediaQuery = _testMediaQuery;
done();
expect(testMediaQuery('only screen')).to.equal(media('only screen').matches);
expect(testMediaQuery('only fake rule')).to.equal(media('only fake rule').matches);
expect(injectElementWithStyles.called).to.be(true);
});
});

it('works', function() {

expect(testMediaQuery('only screen')).to.equal(media('only screen').matches);
expect(testMediaQuery('only fake rule')).to.equal(media('only fake rule').matches);
expect(injectElementWithStyles.called).to.be(true);
});

after(function() {
window.msMatchMedia = msMMOriginal;
window.matchMedia = mmOriginal;
});
});
}

afterEach(function() {
requirejs.undef('testMediaQuery');
Expand Down
6 changes: 3 additions & 3 deletions test/browser/src/testPropsAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ describe('testPropsAll', function() {
testProps = _sinon.spy(_testProps);
cleanup = _cleanup;

requirejs.undef('testDOMProps');
requirejs.undef('testProps');

done();
});

});

beforeEach(function(done) {
requirejs.undef('testDOMProps');
requirejs.undef('testProps');

testDOMProps.reset();
testProps.reset();

Expand Down

0 comments on commit 3b0e142

Please sign in to comment.