Skip to content

Commit

Permalink
[added] warningPrefix option
Browse files Browse the repository at this point in the history
warningPrefix allows one to specify an optional prefix to be added
to the failure message.
  • Loading branch information
matt-royal authored and Caroline Taymor and Matt Royal committed Jul 23, 2015
1 parent 9a28109 commit 2f5f942
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,25 @@ describe('exclusions', () => {
});
});
});

describe('warningPrefix', () => {
var createElement = React.createElement;

let warningPrefix = 'react-a11y ERROR:';
before(() => {
a11y(React, { warningPrefix });
});

after(() => {
React.createElement = createElement;
});

it('adds the prefix to each warning message', () => {
expectWarning(warningPrefix + assertions.tags.img.MISSING_ALT.msg, () => {
<div>
<img id="foo" src="foo.jpg"/>
<img id="bar" src="foo.jpg"/>
</div>;
});
});
});
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var logWarning = (component, failureInfo, options) => {

var handleFailure = (options, reactEl, type, props, failureMsg) => {
var includeSrcNode = options && !!options.includeSrcNode;
var warningPrefix = (options && options.warningPrefix) || '';
var reactComponent = reactEl._owner;

// If a Component instance, use the component's name,
Expand All @@ -138,7 +139,7 @@ var handleFailure = (options, reactEl, type, props, failureMsg) => {
var failureInfo = {
'tagName': name ,
'id': props.id,
'msg': failureMsg
'msg': warningPrefix + failureMsg
};

var notifyOpts = {
Expand Down

0 comments on commit 2f5f942

Please sign in to comment.