jest-react
Version:
Jest matchers and utilities for testing React components.
14 lines (13 loc) • 2.4 kB
JavaScript
/** @license React vundefined
* jest-react.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.
*/
;var d=require("object-assign"),f=require("scheduler/unstable_mock"),h=60103,k=60107;if("function"===typeof Symbol&&Symbol.for){var m=Symbol.for;h=m("react.element");k=m("react.fragment")}var n=Array.isArray,p=null;function q(a){if(null===p)try{var b=("require"+Math.random()).slice(0,7);p=(module&&module[b]).call(module,"timers").setImmediate}catch(c){p=function(a){var b=new MessageChannel;b.port1.onmessage=a;b.port2.postMessage(void 0)}}return p(a)}
function r(a,b){jest.runOnlyPendingTimers();q(function(){try{f.unstable_flushAllWithoutAsserting()?r(a,b):a()}catch(c){b(c)}})}function t(a){try{a()}catch(b){return{pass:!1,message:function(){return b.message}}}return{pass:!0}}function u(a){if(null===a||"string"===typeof a)return a;var b=v(a.children);return{$$typeof:h,type:a.type,key:null,ref:null,props:null===b?a.props:d({},a.props,{children:b}),_owner:null,_store:void 0}}
function v(a){if(null!==a){if(1===a.length)return u(a[0]);if(1<a.length){for(var b=[],c=!0,e="",l=0;l<a.length;l++){var g=u(a[l]);b.push(g);c&&("string"===typeof g?e+=g:null!==g&&(c=!1))}return c?e:b}}return null}
exports.act=function(a){if(void 0===f.unstable_flushAllWithoutAsserting)throw Error("This version of `act` requires a special mock build of Scheduler.");if(!0!==setTimeout._isMockFunction)throw Error("This version of `act` requires Jest's timer mocks (i.e. jest.useFakeTimers).");try{var b=a();if("object"===typeof b&&null!==b&&"function"===typeof b.then)return{then:function(a,c){b.then(function(){r(function(){a()},function(a){c(a)})},function(a){c(a)})}};do var c=f.unstable_flushAllWithoutAsserting();
while(c)}catch(e){throw e;}};exports.unstable_toMatchRenderedOutput=function(a,b){if(0!==a._Scheduler.unstable_clearYields().length)throw Error("Log of yielded values is not empty. Call expect(ReactTestRenderer).unstable_toHaveYielded(...) first.");a=a.toJSON();if(null===a||"string"===typeof a)var c=a;else n(a)?0===a.length?c=null:1===a.length?c=u(a[0]):(a=v(a),c=null===a||"string"===typeof a?a:{$$typeof:h,type:k,key:null,ref:null,props:{children:a},_owner:null,_store:void 0}):c=u(a);return t(function(){expect(c).toEqual(b)})};