Skip to content

Commit a7eb16f

Browse files
author
Erin Doyle
committed
Fixed #16 inappropriately referencing this in a context where this is actually undefined.
1 parent 8e6d829 commit a7eb16f

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"es2015",
44
"stage-0",
55
"react"
6-
]
7-
, "plugins": [
6+
],
7+
"plugins": [
88
"transform-runtime"
99
]
1010
}

src/a11y.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export default class A11y {
1313
*/
1414
constructor(...args) {
1515
const {
16-
React
17-
, ReactDOM
18-
, ...options
19-
} = validate(...args);
16+
React,
17+
ReactDOM,
18+
...options
19+
} = validate(...args);
2020

2121
this.options = options;
2222
this.React = React;
@@ -34,7 +34,7 @@ export default class A11y {
3434
// save old createElement
3535
this._createElement = this.React.createElement;
3636

37-
const that = this;
37+
const _this = this;
3838
this.React.createElement = function (klass, _props = {}, ...children) {
3939
// fix for props = null
4040
const props = _props || {};
@@ -56,16 +56,16 @@ export default class A11y {
5656

5757
const newProps = typeof klass === 'string' ? { ...props, ref } : props;
5858

59-
const reactEl = that._createElement(klass, newProps, ...children);
59+
const reactEl = _this._createElement(klass, newProps, ...children);
6060

6161
// only test html elements
6262
if (typeof klass === 'string') {
63-
const handler = that.failureHandler(reactEl, refs);
63+
const handler = _this.failureHandler(reactEl, refs);
6464
const childrenForTest = children.length === 0
6565
? props.children || []
6666
: children;
6767

68-
that.suite.test(klass, props, childrenForTest, handler);
68+
_this.suite.test(klass, props, childrenForTest, handler);
6969
}
7070

7171
return reactEl;
@@ -122,14 +122,16 @@ export default class A11y {
122122
// TODO: reduce the number of case where ther is no instance
123123
// by forcing every component to have one.
124124
if (browser && !this.__sync && owner && owner._instance) {
125+
const _this = this;
125126
const instance = owner._instance;
127+
126128
// Cannot log a node reference until the component is in the DOM,
127129
// so defer the call until componentDidMount or componentDidUpdate.
128130
after.render(instance, () => {
129131
// unpack the ref
130132
let DOMNode = false;
131133
if (typeof ref === 'string') {
132-
DOMNode = this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
134+
DOMNode = _this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
133135
} else if ('node' in ref) {
134136
DOMNode = ref.node;
135137
} else {

src/after.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const after = (host, name, cb) => {
1515

1616
// override host
1717
host[name] = (...args) => {
18-
// perform original
19-
original.apply(this, args);
20-
// perform cb
21-
cb.apply(this, args);
18+
// perform original
19+
original.apply(host, args);
20+
// perform cb
21+
cb(...args);
2222
};
2323

2424
// save restoring function

0 commit comments

Comments
 (0)