Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ReactWrapper.prototype.getKey = function () {
return this.key()
}
ReactWrapper.prototype.getComputedStyle = function () {
const domNode = this.getDOMNode()
return domNode && window && window.getComputedStyle(domNode)
}
ReactWrapper.prototype.tagName = function () {
const domNode = this.getDOMNode()
return domNode && domNode.tagName.toUpperCase()
}
ReactWrapper.prototype.findText = function (text) {
return this.findWhere(n => n.text() === text)
}
ReactWrapper.prototype.getA11yViolations = function (options, callback) {
checkA11y(this.getDOMNode(), options, callback)
}
const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
const ref = arguments[0]
const instance = this.instance()
// eslint-disable-next-line no-prototype-builtins
if (instance.hasOwnProperty(ref)) {
return new ReactWrapper(instance[ref], true)
} else {
return originalRef.apply(this, arguments)
}
ReactWrapper.prototype.tagName = function () {
const domNode = this.getDOMNode()
return domNode && domNode.tagName.toUpperCase()
}
ReactWrapper.prototype.findText = function (text) {
return this.findWhere(n => n.text() === text)
}
ReactWrapper.prototype.findElementWithText = function (type, text) {
return this.findWhere(n => n.type() === type && n.text() === text)
}
const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
const ref = arguments[0]
const instance = this.instance()
// eslint-disable-next-line no-prototype-builtins
if (instance.hasOwnProperty(ref)) {
return new ReactWrapper(instance[ref], true)
} else if (typeof originalRef === 'function') {
return originalRef.apply(this, arguments)
}
}
module.exports = {
ReactWrapper,
mount
}
}
ReactWrapper.prototype.tagName = function () {
const domNode = this.getDOMNode()
return domNode && domNode.tagName.toUpperCase()
}
ReactWrapper.prototype.findText = function (text) {
return this.findWhere(n => n.text() === text)
}
ReactWrapper.prototype.getA11yViolations = function (options, callback) {
checkA11y(this.getDOMNode(), options, callback)
}
const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
const ref = arguments[0]
const instance = this.instance()
// eslint-disable-next-line no-prototype-builtins
if (instance.hasOwnProperty(ref)) {
return new ReactWrapper(instance[ref], true)
} else {
return originalRef.apply(this, arguments)
}
}
// eslint-disable-next-line import/no-extraneous-dependencies
global.chai.use(require('chai-string'))
// eslint-disable-next-line import/no-extraneous-dependencies
global.chai.use(require('chai-enzyme')())
/* global jest */
/* eslint-disable import/no-extraneous-dependencies */
import Enzyme, { ReactWrapper } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
// TODO remove when enzyme releases https://github.com/airbnb/enzyme/pull/1179
ReactWrapper.prototype.hostNodes = function () {
return this.filterWhere(n => typeof n.type() === 'string');
};
global.requestAnimationFrame = function (cb) { cb(0); };
global.window.cancelAnimationFrame = function () { };
global.createSpyObj = (baseName, methodNames) => {
const obj = {};
for (let i = 0; i < methodNames.length; i += 1) {
obj[methodNames[i]] = jest.fn();
}
return obj;
};
global.document.createRange = () => ({
setStart: () => {},
setEnd: () => {},
}
ReactWrapper.prototype.focus = function () {
this.getDOMNode().focus()
}
ReactWrapper.prototype.focused = function () {
const domNode = this.getDOMNode()
return domNode && domNode === document.activeElement
}
ReactWrapper.prototype.getKey = function () {
return this.key()
}
ReactWrapper.prototype.getComputedStyle = function () {
const domNode = this.getDOMNode()
return domNode && window && window.getComputedStyle(domNode)
}
ReactWrapper.prototype.tagName = function () {
const domNode = this.getDOMNode()
return domNode && domNode.tagName.toUpperCase()
}
ReactWrapper.prototype.findText = function (text) {
return this.findWhere(n => n.text() === text)
}
ReactWrapper.prototype.getA11yViolations = function (options, callback) {
checkA11y(this.getDOMNode(), options, callback)
}
const result = original && original.apply(this, arguments)
after.apply(this, arguments)
return result
}
})(object[methodName], extra)
}
ReactWrapper.prototype.unwrap = function () {
return this.node
}
ReactWrapper.prototype.getAttribute = function (attrName) {
return this.getDOMNode().getAttribute(attrName)
}
ReactWrapper.prototype.dispatchNativeEvent = function (type, attrs) {
const event = new Event(type)
const domNode = this.getDOMNode()
domNode.dispatchEvent(event, attrs)
}
ReactWrapper.prototype.dispatchNativeKeyboardEvent = function (type, keyCode) {
const event = document.createEventObject ? document.createEventObject() : document.createEvent('Events')
if (event.initEvent) {
event.initEvent(type, true, true)
}
event.keyCode = keycode(keyCode)
this.getDOMNode().dispatchEvent(event)
this.simulate('keyUp', { keyCode: keyCode, key: keyCode, which: keyCode })
}
ReactWrapper.prototype.click = function () {
this.simulate('click')
}
ReactWrapper.prototype.mouseOver = function () {
this.simulate('mouseOver')
}
ReactWrapper.prototype.mouseOut = function () {
this.simulate('mouseOut')
}
ReactWrapper.prototype.focus = function () {
this.getDOMNode().focus()
}
ReactWrapper.prototype.focused = function () {
const domNode = this.getDOMNode()
return domNode && domNode === document.activeElement
}
ReactWrapper.prototype.getKey = function () {
return this.key()
}
ReactWrapper.prototype.getComputedStyle = function () {
const domNode = this.getDOMNode()
return domNode && window && window.getComputedStyle(domNode)
}
ReactWrapper.prototype.focused = function () {
const domNode = this.getDOMNode()
return domNode && domNode === document.activeElement
}
ReactWrapper.prototype.getKey = function () {
return this.key()
}
ReactWrapper.prototype.getComputedStyle = function () {
const domNode = this.getDOMNode()
return domNode && window && window.getComputedStyle(domNode)
}
ReactWrapper.prototype.tagName = function () {
const domNode = this.getDOMNode()
return domNode && domNode.tagName.toUpperCase()
}
ReactWrapper.prototype.findText = function (text) {
return this.findWhere(n => n.text() === text)
}
ReactWrapper.prototype.getA11yViolations = function (options, callback) {
checkA11y(this.getDOMNode(), options, callback)
}
const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
const ref = arguments[0]
const instance = this.instance()
}
ReactWrapper.prototype.blur = function () {
this.simulate('blur')
}
ReactWrapper.prototype.focus = function () {
this.getDOMNode().focus()
}
ReactWrapper.prototype.focused = function () {
const domNode = this.getDOMNode()
return domNode && domNode === document.activeElement
}
ReactWrapper.prototype.setValue = function (value) {
const domNode = this.getDOMNode()
this.simulate('focus')
domNode.value = value
this.simulate('keyUp')
this.simulate('keyDown')
this.simulate('change', { target: { value } })
}
ReactWrapper.prototype.getKey = function () {
return this.key()
}
if (event.initEvent) {
event.initEvent(type, true, true)
}
event.keyCode = keycode(keyCode)
this.getDOMNode().dispatchEvent(event)
}
ReactWrapper.prototype.dispatchNativeMouseEvent = function (type, attrs) {
const event = new MouseEvent(type, attrs)
const domNode = this.getDOMNode()
domNode.dispatchEvent(event)
}
ReactWrapper.prototype.keyDown = function (code) {
const keyCode = keycode(code)
this.simulate('keyDown', { keyCode: keyCode, key: keyCode, which: keyCode })
}
ReactWrapper.prototype.keyUp = function (code) {
const keyCode = keycode(code)
this.simulate('keyUp', { keyCode: keyCode, key: keyCode, which: keyCode })
}
ReactWrapper.prototype.click = function () {
this.simulate('click')
}
ReactWrapper.prototype.mouseOver = function () {
this.simulate('mouseOver')
}