Skip to content

Commit

Permalink
Merge pull request #111 from wyattdanger/update-to-use-react-dom
Browse files Browse the repository at this point in the history
Update to use ReactDOM
  • Loading branch information
wyattdanger committed Feb 23, 2016
2 parents 23c35df + 40f1565 commit eb3dd6a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ It's also possible exclude certain tests:

```
a11y(React, { exclude: ['REDUNDANT_ALT'] });
```
```

ReactDOM
--------

You can pass `ReactDOM` to `a11y` for `React 0.14` compatibility.

```
a11y(React, { ReactDOM: ReactDOM });
```
29 changes: 15 additions & 14 deletions lib/__tests__/index-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var React = require('react');
var ReactDOM = require('react-dom');
var assert = require('assert');
var a11y = require('../index');
var assertions = require('../assertions');
Expand Down Expand Up @@ -30,7 +31,7 @@ describe('props', () => {
var createElement = React.createElement;

before(() => {
a11y(React);
a11y(React, { ReactDOM });
});

after(() => {
Expand Down Expand Up @@ -154,7 +155,7 @@ describe('tags', () => {
var createElement = React.createElement;

before(() => {
a11y(React);
a11y(React, { ReactDOM });
});

after(() => {
Expand Down Expand Up @@ -235,7 +236,7 @@ describe('labels', () => {
var fixture;

before(() => {
a11y(React);
a11y(React, { ReactDOM });
});

after(() => {
Expand Down Expand Up @@ -399,7 +400,7 @@ describe('labels', () => {
});

doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><span><Foo/></span></div>, fixture);
ReactDOM.render(<div role="button"><span><Foo/></span></div>, fixture);
});
});

Expand All @@ -413,7 +414,7 @@ describe('labels', () => {
});

doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Foo/></div>, fixture);
ReactDOM.render(<div role="button"><Foo/></div>, fixture);
});
});

Expand All @@ -427,7 +428,7 @@ describe('labels', () => {
});

expectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Foo/></div>, fixture);
ReactDOM.render(<div role="button"><Foo/></div>, fixture);
});
});

Expand All @@ -443,7 +444,7 @@ describe('labels', () => {
});

doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><span><Foo/></span></div>, fixture);
ReactDOM.render(<div role="button"><span><Foo/></span></div>, fixture);
});
});

Expand All @@ -459,7 +460,7 @@ describe('labels', () => {
});

expectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><span><Foo/></span></div>, fixture);
ReactDOM.render(<div role="button"><span><Foo/></span></div>, fixture);
});
});

Expand All @@ -475,7 +476,7 @@ describe('labels', () => {
});

doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><span><Foo/></span></div>, fixture);
ReactDOM.render(<div role="button"><span><Foo/></span></div>, fixture);
});
});

Expand All @@ -489,7 +490,7 @@ describe('labels', () => {
});

expectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Bar/></div>, fixture);
ReactDOM.render(<div role="button"><Bar/></div>, fixture);
});
});

Expand All @@ -513,7 +514,7 @@ describe('labels', () => {
});

doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Bar/><Foo/></div>, fixture);
ReactDOM.render(<div role="button"><Bar/><Foo/></div>, fixture);
});
});

Expand All @@ -535,7 +536,7 @@ describe('labels', () => {
});

expectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Bar/><div/><Foo/></div>, fixture);
ReactDOM.render(<div role="button"><Bar/><div/><Foo/></div>, fixture);
});
});

Expand All @@ -554,7 +555,7 @@ describe('labels', () => {
});

expectWarning(assertions.render.NO_LABEL.msg, () => {
React.render(<div role="button"><Bar/></div>, fixture);
ReactDOM.render(<div role="button"><Bar/></div>, fixture);
});
});

Expand Down Expand Up @@ -597,7 +598,7 @@ describe('includeSrcNode is "asString"', () => {
}
});

var msgs = captureWarnings(() => {React.render(<Bar/>, fixture);});
var msgs = captureWarnings(() => {ReactDOM.render(<Bar/>, fixture);});
var regex = /^Source Node: <(\w+) .+>.*<\/\1>/;
var matches = msgs[assertions.render.NO_LABEL.msg].match(regex);
assert.equal(matches[1], "div");
Expand Down
8 changes: 5 additions & 3 deletions lib/assertions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var after = require('./after');

var React;
var ReactDOM;

exports.setReact = function(R) {
React = R;
exports.setReact = function(_React, _ReactDOM) {
React = _React;
ReactDOM = _ReactDOM || React;
};

var INTERACTIVE = {
Expand Down Expand Up @@ -99,7 +101,7 @@ var hasChildTextNode = (props, children, failureCB) => {
// To account for this, check each Component's HTML after it's
// been mounted.
after(child.type.prototype, 'componentDidMount', function() {
assertLabel(React.findDOMNode(this), context, failureCB);
assertLabel(ReactDOM.findDOMNode(this), context, failureCB);
});

// Return true because the label check is now going to be async
Expand Down
9 changes: 5 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var logWarning = (component, failureInfo, options) => {

if (includeSrcNode && component) {
// TODO:
// 1) Consider using React.findDOMNode() over document.getElementById
// 1) Consider using ReactDOM.findDOMNode() over document.getElementById
// https://github.com/rackt/react-a11y/issues/54
// 2) Consider using ref to expand element element reference logging
// to all element (https://github.com/rackt/react-a11y/issues/55)
Expand Down Expand Up @@ -164,18 +164,19 @@ var createId = function() {
};
}();

var reactA11y = (React, options) => {
var reactA11y = (React, options = {}) => {
const { ReactDOM } = options;

if (!React && !React.createElement) {
throw new Error('Missing parameter: React');
}

assertions.setReact(React);
assertions.setReact(React, ReactDOM);

_createElement = React.createElement;

React.createElement = (type, _props, ...children) => {
var props = _props || {};
options = options || {};

var childrenForTest;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"mocha": "^2.0.1",
"object.assign": "^4.0.3",
"react": "^0.12 || ^0.13 || ^0.14",
"react-dom": "^0.14.7",
"rf-release": "0.4.0",
"webpack": "^1.4.13"
},
Expand Down

0 comments on commit eb3dd6a

Please sign in to comment.