diff --git a/index.js b/index.js index cb6bd69..6fe0a8a 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ const fallbackDescriptorDuplicateCheck = allDescriptors => { throw new Error('Only one fallback image candidate is allowed'); } - if (allDescriptors.x['1']) { + // TODO: Use `?`. + if (allDescriptors.x && allDescriptors.x['1']) { throw new Error('A fallback image is equivalent to a 1x descriptor, providing both is invalid.'); } diff --git a/test.js b/test.js index 3cd1852..d86db6d 100644 --- a/test.js +++ b/test.js @@ -41,6 +41,21 @@ test('parseSrcset() should parse srcset separated without whitespaces', t => { ]); }); +test('parseSrcset() - strict mode', t => { + t.deepEqual( + parseSrcset('images/x.jpg, images/x-retina.jpg 2x', {strict: true}), + [ + { + url: 'images/x.jpg', + }, + { + url: 'images/x-retina.jpg', + density: 2, + }, + ], + ); +}); + test('stringifySrcset() should stringify srcset', t => { const fixture = [ {url: 'banner-HD.jpeg', density: 2},