patchReact()

in src/a11y.js [33:72]


    patchReact() {
        // save old createElement
        this._createElement = this.React.createElement;

        const _this = this;
        this.React.createElement = function (klass, _props = {}, ...children) {
            // fix for props = null
            const props = _props || {};

            // create a refs object to hold the ref.
            // this needs to be an object so that it can be passed
            // by reference, and hold changing state.
            const refs = typeof props.ref === 'string' || typeof props.ref === 'object' ? props.ref : {};
            const ref = typeof props.ref === 'string' || typeof props.ref === 'object' ? props.ref :
                (node) => {
                    refs.node = node;

                    // maintain behaviour when ref prop was already set
                    if (typeof props.ref === 'function') {
                        props.ref(node);
                    }
                };

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

            const reactEl = _this._createElement(klass, newProps, ...children);

            // only test html elements
            if (typeof klass === 'string') {
                const handler = _this.failureHandler(reactEl, refs);
                const childrenForTest = children.length === 0
                    ? props.children || []
                    : children;

                _this.suite.test(klass, props, childrenForTest, handler);
            }

            return reactEl;
        };
    }