From b18f7b3b8ec77ddcdec4ea3fdaf80159ba7f010b Mon Sep 17 00:00:00 2001 From: Viktor Hubert Date: Mon, 27 Feb 2017 00:06:05 +0000 Subject: [PATCH] Made aspect-ratio actually work, and improved the tests --- src/postcss/getConditionsFromQueryParams.js | 4 ++-- .../getConditionsFromQueryParams.spec.js | 20 ++++++++++++++++++- src/postcss/isEmptyObject.spec.js | 10 ++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/postcss/getConditionsFromQueryParams.js b/src/postcss/getConditionsFromQueryParams.js index c3f87fe..7128258 100644 --- a/src/postcss/getConditionsFromQueryParams.js +++ b/src/postcss/getConditionsFromQueryParams.js @@ -14,13 +14,13 @@ export default function getConditionsFromQueryParams (params) { return conditionArr.map((condition) => { let conditionArr = trim(condition, '()'); - conditionArr = conditionArr.match(/([a-z]*)([ :><=]*)([a-z0-9]*)/i); + conditionArr = conditionArr.match(/([a-z-]*)([ :><=]*)([a-z0-9\.]*)/i); conditionArr.shift(); conditionArr = conditionArr.map(trim); if ([ 'landscape', 'portrait' ].indexOf(conditionArr[2]) === -1) { - conditionArr[2] = parseInt(conditionArr[2]); + conditionArr[2] = parseFloat(conditionArr[2]); } return conditionArr; diff --git a/src/postcss/getConditionsFromQueryParams.spec.js b/src/postcss/getConditionsFromQueryParams.spec.js index 419f7ae..af89dcf 100644 --- a/src/postcss/getConditionsFromQueryParams.spec.js +++ b/src/postcss/getConditionsFromQueryParams.spec.js @@ -1,6 +1,6 @@ import getConditionsFromQueryParams from './getConditionsFromQueryParams'; -test('single condition should work with the "<", ">", "<=", ">=" and ":" operators', () => { +test('width condition should work with the "<", ">", "<=", ">=" and ":" operators', () => { expect(getConditionsFromQueryParams('(width >= 42px)')).toEqual([ [ 'width', '>=', 42 ], ]); @@ -13,6 +13,24 @@ test('single condition should work with the "<", ">", "<=", ">=" and ":" operato expect(getConditionsFromQueryParams('(width < 42px)')).toEqual([ [ 'width', '<', 42 ], ]); +}); + +test('aspect-ratio should work with the "<", ">", "<=", ">=" and ":" operators', () => { + expect(getConditionsFromQueryParams('(aspect-ratio >= 0.5)')).toEqual([ + [ 'aspect-ratio', '>=', 0.5 ], + ]); + expect(getConditionsFromQueryParams('(aspect-ratio > 0.5)')).toEqual([ + [ 'aspect-ratio', '>', 0.5 ], + ]); + expect(getConditionsFromQueryParams('(aspect-ratio <= 0.5)')).toEqual([ + [ 'aspect-ratio', '<=', 0.5 ], + ]); + expect(getConditionsFromQueryParams('(aspect-ratio < 0.5)')).toEqual([ + [ 'aspect-ratio', '<', 0.5 ], + ]); +}); + +test('orientations with the : operator', () => { expect(getConditionsFromQueryParams('(orientation: portrait)')).toEqual([ [ 'orientation', ':', 'portrait' ], ]); diff --git a/src/postcss/isEmptyObject.spec.js b/src/postcss/isEmptyObject.spec.js index 46c1783..3b27b66 100644 --- a/src/postcss/isEmptyObject.spec.js +++ b/src/postcss/isEmptyObject.spec.js @@ -13,3 +13,13 @@ test('should return true if object is empty', () => { expect(isEmptyObject(obj)).toBe(false); expect(obj.hasOwnProperty).toHaveBeenCalledTimes(1); }); + +test('should not include properties from the prototype chain', () => { + const parentObj = { parentProperty: 'parent value' }; + const childObj = Object.create(parentObj); + + expect(isEmptyObject(childObj)).toBe(true); + + childObj.childProperty = 'child value'; + expect(isEmptyObject(childObj)).toBe(false); +});