Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2f5f942

Browse files
matt-royalCaroline Taymor and Matt Royal
authored and
Caroline Taymor and Matt Royal
committedJul 23, 2015
[added] warningPrefix option
warningPrefix allows one to specify an optional prefix to be added to the failure message.
1 parent 9a28109 commit 2f5f942

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎lib/__tests__/index-test.js

+22
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,25 @@ describe('exclusions', () => {
637637
});
638638
});
639639
});
640+
641+
describe('warningPrefix', () => {
642+
var createElement = React.createElement;
643+
644+
let warningPrefix = 'react-a11y ERROR:';
645+
before(() => {
646+
a11y(React, { warningPrefix });
647+
});
648+
649+
after(() => {
650+
React.createElement = createElement;
651+
});
652+
653+
it('adds the prefix to each warning message', () => {
654+
expectWarning(warningPrefix + assertions.tags.img.MISSING_ALT.msg, () => {
655+
<div>
656+
<img id="foo" src="foo.jpg"/>
657+
<img id="bar" src="foo.jpg"/>
658+
</div>;
659+
});
660+
});
661+
});

‎lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var logWarning = (component, failureInfo, options) => {
128128

129129
var handleFailure = (options, reactEl, type, props, failureMsg) => {
130130
var includeSrcNode = options && !!options.includeSrcNode;
131+
var warningPrefix = (options && options.warningPrefix) || '';
131132
var reactComponent = reactEl._owner;
132133

133134
// If a Component instance, use the component's name,
@@ -138,7 +139,7 @@ var handleFailure = (options, reactEl, type, props, failureMsg) => {
138139
var failureInfo = {
139140
'tagName': name ,
140141
'id': props.id,
141-
'msg': failureMsg
142+
'msg': warningPrefix + failureMsg
142143
};
143144

144145
var notifyOpts = {

0 commit comments

Comments
 (0)
Please sign in to comment.