Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Incomplete fallback message was missing #3302

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions build/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,10 @@ function buildRules(grunt, options, commons, callback) {
}

function getIncompleteMsg(summaries) {
var result = {};
summaries.forEach(function(summary) {
if (
summary.incompleteFallbackMessage &&
doTRegex.test(summary.incompleteFallbackMessage)
) {
result = doT.template(summary.incompleteFallbackMessage).toString();
}
var summary = summaries.find(function(summary) {
return typeof summary.incompleteFallbackMessage === 'string';
});
return result;
return summary ? summary.incompleteFallbackMessage : '';
}

function replaceFunctions(string) {
Expand Down
15 changes: 9 additions & 6 deletions lib/core/reporters/helpers/incomplete-fallback-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* This mechanism allows the string to be localized.
* @return {String}
*/
function incompleteFallbackMessage() {
return typeof axe._audit.data.incompleteFallbackMessage === 'function'
? axe._audit.data.incompleteFallbackMessage()
: axe._audit.data.incompleteFallbackMessage;
export default function incompleteFallbackMessage() {
let { incompleteFallbackMessage } = axe._audit.data;
if (typeof incompleteFallbackMessage === 'function') {
incompleteFallbackMessage = incompleteFallbackMessage();
}
if (typeof incompleteFallbackMessage !== 'string') {
return '';
}
return incompleteFallbackMessage;
}

export default incompleteFallbackMessage;
47 changes: 43 additions & 4 deletions test/core/reporters/helpers/incomplete-fallback-msg.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
describe('helpers.incompleteFallbackMessage', function() {
'use strict';
beforeEach(function() {

it('returns a non-empty string by default', function () {
var summary = helpers.incompleteFallbackMessage();
assert.typeOf(summary, 'string');
assert.notEqual(summary, '');
});

it('should return a string', function() {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: 'Dogs are the best'
}
});
});

it('should return a string', function() {
var summary = helpers.incompleteFallbackMessage();
assert.equal(summary, 'Dogs are the best');
});
Expand All @@ -29,4 +33,39 @@ describe('helpers.incompleteFallbackMessage', function() {
var summary = helpers.incompleteFallbackMessage();
assert.equal(summary, 'Dogs are the best');
});

describe('when passed an invalid value', function () {
it('returns `` when set to an object', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: {}
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});

it('returns `` when set to null', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: null
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});

it('returns `` when set to undefined', function () {
axe._load({
messages: {},
rules: [],
data: {
incompleteFallbackMessage: undefined
}
});
assert.equal(helpers.incompleteFallbackMessage(), '');
});
});
});