Skip to content

Commit

Permalink
fix(utils): handle missing details.items (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Oct 29, 2020
1 parent 56fe544 commit 0449e6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/utils/src/assertions.js
Expand Up @@ -40,7 +40,7 @@ const AUDIT_TYPE_VALUE_GETTERS = {
if (result.scoreDisplayMode === 'informative') return 0;
return undefined;
},
maxLength: result => result.details && result.details.items && result.details.items.length,
maxLength: result => (result.details && result.details.items && result.details.items.length) || 0,
maxNumericValue: result => result.numericValue,
};

Expand Down
21 changes: 21 additions & 0 deletions packages/utils/test/assertions.test.js
Expand Up @@ -209,6 +209,27 @@ describe('getAllAssertionResults', () => {
expect(results).toMatchObject([{actual: 0.8, expected: 0.9}]);
});

it('should assume a default items length of 0', () => {
const assertions = {
'first-contentful-paint': ['error', {maxLength: 10}],
};

const results = getAllAssertionResults({assertions, includePassedAssertions: true}, lhrs);
expect(results).toEqual([
{
actual: 0,
auditId: 'first-contentful-paint',
expected: 10,
level: 'error',
name: 'maxLength',
operator: '<=',
passed: true,
url: 'http://page-1.com',
values: [0, 0],
},
]);
});

it('should warn on incorrect assertion type', () => {
const assertions = {
'network-requests': ['error', {maxNumericValue: 10}],
Expand Down

0 comments on commit 0449e6e

Please sign in to comment.