UNPKG

react-test-renderer

Version:

React package for snapshot testing.

35 lines (33 loc) • 11.9 kB
/** @license React v16.10.0 * react-test-renderer-shallow.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict';var k=require("object-assign"),m=require("react"),n=require("react-is"),p=require("prop-types/checkPropTypes");function q(b){for(var d=b.message,a="https://reactjs.org/docs/error-decoder.html?invariant="+d,c=1;c<arguments.length;c++)a+="&args[]="+encodeURIComponent(arguments[c]);b.message="Minified React error #"+d+"; visit "+a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings. ";return b} var r=/^(.*)[\\\/]/,t="function"===typeof Symbol&&Symbol.for,u=t?Symbol.for("react.portal"):60106,v=t?Symbol.for("react.fragment"):60107,w=t?Symbol.for("react.strict_mode"):60108,x=t?Symbol.for("react.profiler"):60114,y=t?Symbol.for("react.provider"):60109,z=t?Symbol.for("react.context"):60110,A=t?Symbol.for("react.forward_ref"):60112,B=t?Symbol.for("react.suspense"):60113,C=t?Symbol.for("react.suspense_list"):60120,D=t?Symbol.for("react.memo"):60115,E=t?Symbol.for("react.lazy"):60116,F=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; F.hasOwnProperty("ReactCurrentDispatcher")||(F.ReactCurrentDispatcher={current:null});F.hasOwnProperty("ReactCurrentBatchConfig")||(F.ReactCurrentBatchConfig={suspense:null}); function G(b){if(null==b)return null;if("function"===typeof b)return b.displayName||b.name||null;if("string"===typeof b)return b;switch(b){case v:return"Fragment";case u:return"Portal";case x:return"Profiler";case w:return"StrictMode";case B:return"Suspense";case C:return"SuspenseList"}if("object"===typeof b)switch(b.$$typeof){case z:return"Context.Consumer";case y:return"Context.Provider";case A:var d=b.render;d=d.displayName||d.name||"";return b.displayName||(""!==d?"ForwardRef("+d+")":"ForwardRef"); case D:return G(b.type);case E:if(b=1===b._status?b._result:null)return G(b)}return null}function H(b,d){return b===d&&(0!==b||1/b===1/d)||b!==b&&d!==d}var I="function"===typeof Object.is?Object.is:H,J=Object.prototype.hasOwnProperty;function K(b,d){if(I(b,d))return!0;if("object"!==typeof b||null===b||"object"!==typeof d||null===d)return!1;var a=Object.keys(b),c=Object.keys(d);if(a.length!==c.length)return!1;for(c=0;c<a.length;c++)if(!J.call(d,a[c])||!I(b[a[c]],d[a[c]]))return!1;return!0} var L=F.ReactCurrentDispatcher,M={},N=function(){function b(a){this._renderer=a;this._callbacks=[]}var d=b.prototype;d._enqueueCallback=function(a,c){"function"===typeof a&&c&&this._callbacks.push({callback:a,publicInstance:c})};d._invokeCallbacks=function(){var a=this._callbacks;this._callbacks=[];a.forEach(function(a){a.callback.call(a.publicInstance)})};d.isMounted=function(){return!!this._renderer._element};d.enqueueForceUpdate=function(a,c){this._enqueueCallback(c,a);this._renderer._forcedUpdate= !0;this._renderer.render(this._renderer._element,this._renderer._context)};d.enqueueReplaceState=function(a,c,e){this._enqueueCallback(e,a);this._renderer._newState=c;this._renderer.render(this._renderer._element,this._renderer._context)};d.enqueueSetState=function(a,c,e){this._enqueueCallback(e,a);e=this._renderer._newState||a.state;"function"===typeof c&&(c=c.call(a,e,a.props));null!==c&&void 0!==c&&(this._renderer._newState=k({},e,{},c),this._renderer.render(this._renderer._element,this._renderer._context))}; return b}();function O(){return{memoizedState:null,queue:null,next:null}}function P(b,d){return"function"===typeof d?d(b):d} var S=function(){function b(){this._reset()}var d=b.prototype;d._reset=function(){this._rendered=this._newState=this._instance=this._element=this._context=null;this._forcedUpdate=this._rendering=!1;this._updater=new N(this);this._dispatcher=this._createDispatcher();this._firstWorkInProgressHook=this._workInProgressHook=null;this._didScheduleRenderPhaseUpdate=this._isReRender=!1;this._renderPhaseUpdates=null;this._numberOfReRenders=0};d._validateCurrentlyRenderingComponent=function(){if(!this._rendering|| this._instance)throw q(Error(321));};d._createDispatcher=function(){function a(){e._validateCurrentlyRenderingComponent()}function c(a,c,b){e._validateCurrentlyRenderingComponent();e._createWorkInProgressHook();var d=e._workInProgressHook;if(e._isReRender){b=d.queue;c=b.dispatch;if(0<e._numberOfReRenders){if(null!==e._renderPhaseUpdates){var f=e._renderPhaseUpdates.get(b);if(void 0!==f){e._renderPhaseUpdates.delete(b);b=d.memoizedState;do b=a(b,f.action),f=f.next;while(null!==f);d.memoizedState=b; return[b,c]}}return[d.memoizedState,c]}f=d.memoizedState;var g=b.first;if(null!==g){do f=a(f,g.action),g=g.next;while(null!==g);b.first=null;d.memoizedState=f}return[f,c]}a=a===P?"function"===typeof c?c():c:void 0!==b?b(c):c;d.memoizedState=a;a=d.queue={first:null,dispatch:null};a=a.dispatch=e._dispatchAction.bind(e,a);return[d.memoizedState,a]}var e=this;return{readContext:function(a){return a._currentValue},useCallback:function(a){return a},useContext:function(a){e._validateCurrentlyRenderingComponent(); return a._currentValue},useDebugValue:a,useEffect:a,useImperativeHandle:a,useLayoutEffect:a,useMemo:function(a,c){e._validateCurrentlyRenderingComponent();e._createWorkInProgressHook();c=void 0!==c?c:null;if(null!==e._workInProgressHook&&null!==e._workInProgressHook.memoizedState){var b=e._workInProgressHook.memoizedState,d=b[1];if(null!==c){a:if(null===d)d=!1;else{for(var f=0;f<d.length&&f<c.length;f++)if(!I(c[f],d[f])){d=!1;break a}d=!0}if(d)return b[0]}}a=a();e._workInProgressHook.memoizedState= [a,c];return a},useReducer:c,useRef:function(a){e._validateCurrentlyRenderingComponent();e._createWorkInProgressHook();var c=e._workInProgressHook.memoizedState;return null===c?(a={current:a},e._workInProgressHook.memoizedState=a):c},useState:function(a){return c(P,a)},useResponder:function(a,c){return{props:c,responder:a}}}};d._dispatchAction=function(a,c){if(!(25>this._numberOfReRenders))throw q(Error(301));if(this._rendering){this._didScheduleRenderPhaseUpdate=!0;c={action:c,next:null};var e=this._renderPhaseUpdates; null===e&&(this._renderPhaseUpdates=e=new Map);var b=e.get(a);if(void 0===b)e.set(a,c);else{for(a=b;null!==a.next;)a=a.next;a.next=c}}else{c={action:c,next:null};e=a.first;if(null===e)a.first=c;else{for(;null!==e.next;)e=e.next;e.next=c}this.render(this._element,this._context)}};d._createWorkInProgressHook=function(){null===this._workInProgressHook?null===this._firstWorkInProgressHook?(this._isReRender=!1,this._firstWorkInProgressHook=this._workInProgressHook=O()):(this._isReRender=!0,this._workInProgressHook= this._firstWorkInProgressHook):null===this._workInProgressHook.next?(this._isReRender=!1,this._workInProgressHook=this._workInProgressHook.next=O()):(this._isReRender=!0,this._workInProgressHook=this._workInProgressHook.next);return this._workInProgressHook};d._finishHooks=function(a,c){this._didScheduleRenderPhaseUpdate?(this._didScheduleRenderPhaseUpdate=!1,this._numberOfReRenders+=1,this._workInProgressHook=null,this._rendering=!1,this.render(a,c)):(this._renderPhaseUpdates=this._workInProgressHook= null,this._numberOfReRenders=0)};d.getMountedInstance=function(){return this._instance};d.getRenderOutput=function(){return this._rendered};d.render=function(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:M;if(!m.isValidElement(a))throw q(Error(12),"function"===typeof a?" Instead of passing a component class, make sure to instantiate it by passing it to React.createElement.":"");if("string"===typeof a.type)throw q(Error(13),a.type);if(!n.isForwardRef(a)&&"function"!==typeof a.type&& !n.isMemo(a.type))throw q(Error(249),Array.isArray(a.type)?"array":null===a.type?"null":typeof a.type);if(!this._rendering){null!=this._element&&this._element.type!==a.type&&this._reset();var b=n.isMemo(a.type)?a.type.type:a.type,d=this._element;this._rendering=!0;this._element=a;var g;if((g=b.contextTypes)&&c){var l={},h;for(h in g)l[h]=c[h];g=l}else g=M;this._context=g;n.isMemo(a.type)&&b.propTypes&&(Q=a,p(b.propTypes,a.props,"prop",G(b),R));if(this._instance)this._updateClassComponent(b,a,this._context); else if(b.prototype&&b.prototype.isReactComponent)this._instance=new b(a.props,this._context,this._updater),"function"===typeof b.getDerivedStateFromProps&&(c=b.getDerivedStateFromProps.call(null,a.props,this._instance.state),null!=c&&(this._instance.state=k({},this._instance.state,c))),b.contextTypes&&(Q=a,c=(c=this._instance)&&c.constructor,p(b.contextTypes,this._context,"context",b.displayName||c&&c.displayName||b.name||c&&c.name||null,R),Q=null),this._mountClassComponent(b,a,this._context);else if(g= !0,n.isMemo(a.type)&&null!==d&&(a.type.compare||K)(d.props,a.props)&&(g=!1),g){d=L.current;L.current=this._dispatcher;try{if(b.$$typeof===n.ForwardRef){if("function"!==typeof b.render)throw q(Error(322),typeof b.render);this._rendered=b.render.call(void 0,a.props,a.ref)}else this._rendered=b(a.props,this._context)}finally{L.current=d}this._finishHooks(a,c)}this._rendering=!1;this._updater._invokeCallbacks();return this.getRenderOutput()}};d.unmount=function(){this._instance&&"function"===typeof this._instance.componentWillUnmount&& this._instance.componentWillUnmount();this._reset()};d._mountClassComponent=function(a,b,d){this._instance.context=d;this._instance.props=b.props;this._instance.state=this._instance.state||null;this._instance.updater=this._updater;if("function"===typeof this._instance.UNSAFE_componentWillMount||"function"===typeof this._instance.componentWillMount)b=this._newState,"function"!==typeof a.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillMount&& this._instance.componentWillMount(),"function"===typeof this._instance.UNSAFE_componentWillMount&&this._instance.UNSAFE_componentWillMount()),b!==this._newState&&(this._instance.state=this._newState||M);this._rendered=this._instance.render()};d._updateClassComponent=function(a,b,d){b=b.props;var c=this._instance.state||M,e=this._instance.props;e!==b&&"function"!==typeof a.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillReceiveProps&& this._instance.componentWillReceiveProps(b,d),"function"===typeof this._instance.UNSAFE_componentWillReceiveProps&&this._instance.UNSAFE_componentWillReceiveProps(b,d));var l=this._newState||c;if("function"===typeof a.getDerivedStateFromProps){var h=a.getDerivedStateFromProps.call(null,b,l);null!=h&&(l=k({},l,h))}h=!0;this._forcedUpdate?(h=!0,this._forcedUpdate=!1):"function"===typeof this._instance.shouldComponentUpdate?h=!!this._instance.shouldComponentUpdate(b,l,d):a.prototype&&a.prototype.isPureReactComponent&& (h=!K(e,b)||!K(c,l));h&&"function"!==typeof a.getDerivedStateFromProps&&"function"!==typeof this._instance.getSnapshotBeforeUpdate&&("function"===typeof this._instance.componentWillUpdate&&this._instance.componentWillUpdate(b,l,d),"function"===typeof this._instance.UNSAFE_componentWillUpdate&&this._instance.UNSAFE_componentWillUpdate(b,l,d));this._instance.context=d;this._instance.props=b;this._instance.state=l;this._newState=null;h&&(this._rendered=this._instance.render())};return b}(); S.createRenderer=function(){return new S};var Q=null;function T(b){if(null==b)return"#empty";if("string"===typeof b||"number"===typeof b)return"#text";if("string"===typeof b.type)return b.type;b=n.isMemo(b.type)?b.type.type:b.type;return b.displayName||b.name||"Unknown"}function R(){var b="";if(Q){var d=T(Q),a=Q._owner,c=Q._source;a=a&&G(a.type);var e="";c?e=" (at "+c.fileName.replace(r,"")+":"+c.lineNumber+")":a&&(e=" (created by "+a+")");b+="\n in "+(d||"Unknown")+e}return b} var U={default:S},V=U&&S||U;module.exports=V.default||V;