wrapito 13.3.1-beta6 → 13.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -84,6 +84,34 @@ Add this line in your project setup (vite/cra):
84
84
  setupFiles: ['./src/setupTests.tsx']
85
85
  ```
86
86
 
87
+ #### warnOnPendingRequests
88
+
89
+ When rendering a full application, some API calls may still be pending when the test finishes. This can lead to flaky
90
+ tests if those pending requests resolve after the test cleanup phase.
91
+
92
+ By enabling `warnOnPendingRequests`, wrapito will log a warning to the console whenever a fetch call is detected after
93
+ a test has finished, including the request URL, method and the name of the test that left it pending. This helps
94
+ identify tests that need proper cleanup or `await` handling.
95
+
96
+ ```js
97
+ import { configure } from 'wrapito'
98
+
99
+ configure({
100
+ ...configuration,
101
+ warnOnPendingRequests: true,
102
+ })
103
+ ```
104
+
105
+ When a pending request is detected, you will see a warning like:
106
+
107
+ ```
108
+ 🌯 wrapito
109
+ ⚠️ pending request detected after test finished:
110
+ URL: https://my-host/api/products/
111
+ METHOD: get
112
+ TEST: should render the product list
113
+ ```
114
+
87
115
  ## 🏰 Builder API
88
116
 
89
117
  #### withMocks (Deprecated)
package/dist/index.js CHANGED
@@ -3,14 +3,13 @@ ${d.default.white.bold.bgRed("wrapito")} ${d.default.redBright.bold("cannot find
3
3
  ${d.default.greenBright(`URL: ${e.url}`)}
4
4
  ${d.default.greenBright(`METHOD: ${e.method?.toLowerCase()}`)}
5
5
  ${d.default.greenBright(`REQUEST BODY: ${e._bodyInit}`)}
6
- `),F=async(e,t,n)=>{let s=e.find($(t));if(!s)return n&&Oe(t),_();let{multipleResponses:r}=s;if(!r)return L(s);let o=r.find(i=>!i.hasBeenReturned);if(!o){n&&Te(s);return}return o.hasBeenReturned=!0,L(o)},G=(e=[],t=!1)=>{global.window.fetch.mockImplementation((s,r)=>{if(typeof s=="string"){let i=new Request(s,r);return F(e,i,t)}return F(e,s,t)})},Te=e=>{let t=`\u{1F32F} Wrapito: Missing response in the multipleResponses
7
- array for path ${e.path} and method ${e.method}.`,n=d.default.greenBright(t);console.warn(n)},V=e=>{global.window.fetch.mockImplementation((t,n)=>{let s=typeof t=="string"?t:t.url,r=n?.method||(typeof t!="string"?t.method:"GET");return console.warn(`
6
+ `),F=async(e,t,n)=>{let s=e.find($(t));if(!s)return n&&Oe(t),_();let{multipleResponses:r}=s;if(!r)return L(s);let o=r.find(i=>!i.hasBeenReturned);if(!o){n&&Te(s);return}return o.hasBeenReturned=!0,L(o)},G=(e=[],t=!1)=>{global.window.fetch.mockImplementation((s,r)=>{if(typeof s=="string"){let i=new Request(s,r);return F(e,i,t)}return F(e,s,t)})},Te=e=>{let t=`\u{1F32F} Wrapito: Missing response in the multipleResponses array for path ${e.path} and method ${e.method}.`,n=d.default.greenBright(t);console.warn(n)},V=e=>{let t=global.window.fetch.getMockImplementation();global.window.fetch.mockImplementation((n,s)=>{let r=typeof n=="string"?n:n.url,o=s?.method||(typeof n!="string"?n.method:"GET");return console.warn(`
8
7
  ${d.default.white.bold.bgYellow(" \u{1F32F} wrapito ")}
9
8
  ${d.default.yellowBright.bold("\u26A0\uFE0F pending request detected after test finished:")}
10
- ${d.default.greenBright(`URL: ${s}`)}
11
- ${d.default.greenBright(`METHOD: ${r?.toLowerCase()}`)}
9
+ ${d.default.greenBright(`URL: ${r}`)}
10
+ ${d.default.greenBright(`METHOD: ${o?.toLowerCase()}`)}
12
11
  ${e?` ${d.default.greenBright(`TEST: ${e}`)}
13
- `:""}`),_()})};var C,R=e=>{C={...C,...e}},w=()=>({...C});function q(e,t){if(!e)throw new Error(t)}function I(e,t){return typeof t===e}function Ee(e){return e instanceof Promise}function D(e,t,n){Object.defineProperty(e,t,n)}function x(e,t,n){Object.defineProperty(e,t,{value:n})}var M=Symbol.for("tinyspy:spy"),qe=new Set,Pe=e=>{e.called=!1,e.callCount=0,e.calls=[],e.results=[],e.next=[]},Ue=e=>(D(e,M,{value:{reset:()=>Pe(e[M])}}),e[M]),P=e=>e[M]||Ue(e);function We(e){q(I("function",e)||I("undefined",e),"cannot spy on a non-function value");let t=function(...s){let r=P(t);r.called=!0,r.callCount++,r.calls.push(s);let o=r.next.shift();if(o){r.results.push(o);let[u,a]=o;if(u==="ok")return a;throw a}let i,l="ok";if(r.impl)try{new.target?i=Reflect.construct(r.impl,s,new.target):i=r.impl.apply(this,s),l="ok"}catch(u){throw i=u,l="error",r.results.push([l,u]),u}let c=[l,i];if(Ee(i)){let u=i.then(a=>c[1]=a).catch(a=>{throw c[0]="error",c[1]=a,a});Object.assign(u,i),i=u}return r.results.push(c),i};x(t,"_isMockFunction",!0),x(t,"length",e?e.length:0),x(t,"name",e&&e.name||"spy");let n=P(t);return n.reset(),n.impl=e,t}var Q=(e,t)=>Object.getOwnPropertyDescriptor(e,t),J=(e,t)=>{t!=null&&typeof t=="function"&&t.prototype!=null&&Object.setPrototypeOf(e.prototype,t.prototype)};function Y(e,t,n){q(!I("undefined",e),"spyOn could not find an object to spy upon"),q(I("object",e)||I("function",e),"cannot spyOn on a primitive value");let[s,r]=(()=>{if(!I("object",t))return[t,"value"];if("getter"in t&&"setter"in t)throw new Error("cannot spy on both getter and setter");if("getter"in t)return[t.getter,"get"];if("setter"in t)return[t.setter,"set"];throw new Error("specify getter or setter to spy on")})(),o=Q(e,s),i=Object.getPrototypeOf(e),l=i&&Q(i,s),c=o||l;q(c||s in e,`${String(s)} does not exist`);let u=!1;r==="value"&&c&&!c.value&&c.get&&(r="get",u=!0,n=c.get());let a;c?a=c[r]:r!=="value"?a=()=>e[s]:a=e[s],n||(n=a);let m=We(n);r==="value"&&J(m,a);let p=f=>{let{value:k,...W}=c||{configurable:!0,writable:!0};r!=="value"&&delete W.writable,W[r]=f,D(e,s,W)},y=()=>c?D(e,s,c):p(a),g=m[M];return x(g,"restore",y),x(g,"getOriginal",()=>u?a():a),x(g,"willCall",f=>(g.impl=f,m)),p(u?()=>(J(m,n),m):m),qe.add(m),m}var ve=new Set,Ce=0;function De(e){let t=e,n,s=[],r=[],o=P(e),i={get calls(){return o.calls},get instances(){return s},get invocationCallOrder(){return r},get results(){return o.results.map(([p,y])=>({type:p==="error"?"throw":"return",value:y}))},get lastCall(){return o.calls[o.calls.length-1]}},l=[],c=!1;function u(...p){return s.push(this),r.push(++Ce),(c?n:l.shift()||n||o.getOriginal()||(()=>{})).apply(this,p)}let a=t.name;t.getMockName=()=>a||"vi.fn()",t.mockName=p=>(a=p,t),t.mockClear=()=>(o.reset(),s=[],r=[],t),t.mockReset=()=>(t.mockClear(),n=()=>{},l=[],t),t.mockRestore=()=>(t.mockReset(),o.restore(),n=void 0,t),t.getMockImplementation=()=>n,t.mockImplementation=p=>(n=p,o.willCall(u),t),t.mockImplementationOnce=p=>(l.push(p),t);function m(p,y){let g=n;n=p,o.willCall(u),c=!0;let f=()=>{n=g,c=!1},k=y();return k instanceof Promise?k.then(()=>(f(),t)):(f(),t)}return t.withImplementation=m,t.mockReturnThis=()=>t.mockImplementation(function(){return this}),t.mockReturnValue=p=>t.mockImplementation(()=>p),t.mockReturnValueOnce=p=>t.mockImplementationOnce(()=>p),t.mockResolvedValue=p=>t.mockImplementation(()=>Promise.resolve(p)),t.mockResolvedValueOnce=p=>t.mockImplementationOnce(()=>Promise.resolve(p)),t.mockRejectedValue=p=>t.mockImplementation(()=>Promise.reject(p)),t.mockRejectedValueOnce=p=>t.mockImplementationOnce(()=>Promise.reject(p)),Object.defineProperty(t,"mock",{get:()=>i}),o.willCall(u),ve.add(t),t}var z=e=>De(Y({spy:e||(()=>{})},"spy"));beforeEach(()=>{global.fetch=z()});afterEach(()=>{let{warnOnPendingRequests:e}=h();if(e){let t=expect.getState?.()?.currentTestName;V(t)}});var He=e=>(R({Component:e,responses:[],props:{},path:"",hasPath:!1,interactionConfig:void 0,debug:process.env.npm_config_debugRequests==="true"}),b()),b=()=>{let e=je();return{withProps:$e,withNetwork:Fe,withInteraction:Le,atPath:_e,debugRequests:Ge,mount:Ve,...e}},Se=e=>{let t=w(),n=[...t.responses,...e];R({...t,responses:n})},Be=(e,t)=>(t({addResponses:Se},e),b()),Ne=(e,t)=>{let{extend:n}=h(),s=n[t];return{...e,[t]:(...r)=>Be(r,s)}},je=()=>{let{extend:e}=h();return Object.keys(e).reduce(Ne,{})},$e=e=>{let t=w();return R({...t,props:e}),b()},Le=e=>{let t=w();return R({...t,interactionConfig:e}),b()},Fe=(e=[])=>{let t=w(),n=Array.isArray(e)?e:[e];return R({...t,responses:[...t.responses,...n]}),b()},_e=(e,t)=>{let n=w();return R({...n,historyState:t,path:e,hasPath:!0}),b()},Ge=()=>{let e=w();return R({...e,debug:!0}),b()},Ve=()=>{let{portal:e,portals:t,changeRoute:n,history:s,mount:r,interaction:o}=h(),{Component:i,props:l,responses:c,path:u,hasPath:a,debug:m,historyState:p,interactionConfig:y}=w(),g=i;e&&X(e),t&&Qe(t),a&&s&&(console.warn("wrapito WARNING: history is DEPRECATED. Pass a changeRoute function to the config instead."),console.warn("Read about changeRoute in: https://github.com/mercadona/wrapito#changeRoute"),s.push(u,p)),a&&!s&&n(u),G(c,m);let f=r(K.createElement(g,{...l}));if(o){let k=o.setup?o.setup(o.userLib,y):o.userLib;return{...f,user:k}}return{...f,user:void 0}},X=e=>{if(document.getElementById(e))return;let t=document.createElement("div");t.setAttribute("id",e),t.setAttribute("data-testid",e),document.body.appendChild(t)},Qe=e=>{e.forEach(t=>{X(t)})};var H=require("jest-diff"),S=(e,t)=>{let n=t?.host?`\u{1F32F} Wrapito: ${t?.host}${e} ain't got called`:`\u{1F32F} Wrapito: ${e} ain't got called`;return{pass:!1,message:()=>n}},Z=(e,t,n)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: ${e} is called ${n} times, you expected ${t} times`}),ee=(e,t)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch method does not match, expected ${e} received ${t??"none"}`}),te=(e,t)=>{let n=t.map(s=>(0,H.diff)(e,s)).join(`
12
+ `:""}`),t?t(n,s):_()})};var C,R=e=>{C={...C,...e}},w=()=>({...C});function q(e,t){if(!e)throw new Error(t)}function I(e,t){return typeof t===e}function Ee(e){return e instanceof Promise}function D(e,t,n){Object.defineProperty(e,t,n)}function x(e,t,n){Object.defineProperty(e,t,{value:n})}var M=Symbol.for("tinyspy:spy"),qe=new Set,Pe=e=>{e.called=!1,e.callCount=0,e.calls=[],e.results=[],e.next=[]},Ue=e=>(D(e,M,{value:{reset:()=>Pe(e[M])}}),e[M]),P=e=>e[M]||Ue(e);function We(e){q(I("function",e)||I("undefined",e),"cannot spy on a non-function value");let t=function(...s){let r=P(t);r.called=!0,r.callCount++,r.calls.push(s);let o=r.next.shift();if(o){r.results.push(o);let[u,a]=o;if(u==="ok")return a;throw a}let i,l="ok";if(r.impl)try{new.target?i=Reflect.construct(r.impl,s,new.target):i=r.impl.apply(this,s),l="ok"}catch(u){throw i=u,l="error",r.results.push([l,u]),u}let c=[l,i];if(Ee(i)){let u=i.then(a=>c[1]=a).catch(a=>{throw c[0]="error",c[1]=a,a});Object.assign(u,i),i=u}return r.results.push(c),i};x(t,"_isMockFunction",!0),x(t,"length",e?e.length:0),x(t,"name",e&&e.name||"spy");let n=P(t);return n.reset(),n.impl=e,t}var Q=(e,t)=>Object.getOwnPropertyDescriptor(e,t),J=(e,t)=>{t!=null&&typeof t=="function"&&t.prototype!=null&&Object.setPrototypeOf(e.prototype,t.prototype)};function Y(e,t,n){q(!I("undefined",e),"spyOn could not find an object to spy upon"),q(I("object",e)||I("function",e),"cannot spyOn on a primitive value");let[s,r]=(()=>{if(!I("object",t))return[t,"value"];if("getter"in t&&"setter"in t)throw new Error("cannot spy on both getter and setter");if("getter"in t)return[t.getter,"get"];if("setter"in t)return[t.setter,"set"];throw new Error("specify getter or setter to spy on")})(),o=Q(e,s),i=Object.getPrototypeOf(e),l=i&&Q(i,s),c=o||l;q(c||s in e,`${String(s)} does not exist`);let u=!1;r==="value"&&c&&!c.value&&c.get&&(r="get",u=!0,n=c.get());let a;c?a=c[r]:r!=="value"?a=()=>e[s]:a=e[s],n||(n=a);let m=We(n);r==="value"&&J(m,a);let p=f=>{let{value:k,...W}=c||{configurable:!0,writable:!0};r!=="value"&&delete W.writable,W[r]=f,D(e,s,W)},y=()=>c?D(e,s,c):p(a),g=m[M];return x(g,"restore",y),x(g,"getOriginal",()=>u?a():a),x(g,"willCall",f=>(g.impl=f,m)),p(u?()=>(J(m,n),m):m),qe.add(m),m}var ve=new Set,Ce=0;function De(e){let t=e,n,s=[],r=[],o=P(e),i={get calls(){return o.calls},get instances(){return s},get invocationCallOrder(){return r},get results(){return o.results.map(([p,y])=>({type:p==="error"?"throw":"return",value:y}))},get lastCall(){return o.calls[o.calls.length-1]}},l=[],c=!1;function u(...p){return s.push(this),r.push(++Ce),(c?n:l.shift()||n||o.getOriginal()||(()=>{})).apply(this,p)}let a=t.name;t.getMockName=()=>a||"vi.fn()",t.mockName=p=>(a=p,t),t.mockClear=()=>(o.reset(),s=[],r=[],t),t.mockReset=()=>(t.mockClear(),n=()=>{},l=[],t),t.mockRestore=()=>(t.mockReset(),o.restore(),n=void 0,t),t.getMockImplementation=()=>n,t.mockImplementation=p=>(n=p,o.willCall(u),t),t.mockImplementationOnce=p=>(l.push(p),t);function m(p,y){let g=n;n=p,o.willCall(u),c=!0;let f=()=>{n=g,c=!1},k=y();return k instanceof Promise?k.then(()=>(f(),t)):(f(),t)}return t.withImplementation=m,t.mockReturnThis=()=>t.mockImplementation(function(){return this}),t.mockReturnValue=p=>t.mockImplementation(()=>p),t.mockReturnValueOnce=p=>t.mockImplementationOnce(()=>p),t.mockResolvedValue=p=>t.mockImplementation(()=>Promise.resolve(p)),t.mockResolvedValueOnce=p=>t.mockImplementationOnce(()=>Promise.resolve(p)),t.mockRejectedValue=p=>t.mockImplementation(()=>Promise.reject(p)),t.mockRejectedValueOnce=p=>t.mockImplementationOnce(()=>Promise.reject(p)),Object.defineProperty(t,"mock",{get:()=>i}),o.willCall(u),ve.add(t),t}var z=e=>De(Y({spy:e||(()=>{})},"spy"));beforeEach(()=>{global.fetch=z()});afterEach(()=>{let{warnOnPendingRequests:e}=h();if(e){let t=expect.getState?.()?.currentTestName;V(t)}});var He=e=>(R({Component:e,responses:[],props:{},path:"",hasPath:!1,interactionConfig:void 0,debug:process.env.npm_config_debugRequests==="true"}),b()),b=()=>{let e=je();return{withProps:$e,withNetwork:Fe,withInteraction:Le,atPath:_e,debugRequests:Ge,mount:Ve,...e}},Se=e=>{let t=w(),n=[...t.responses,...e];R({...t,responses:n})},Be=(e,t)=>(t({addResponses:Se},e),b()),Ne=(e,t)=>{let{extend:n}=h(),s=n[t];return{...e,[t]:(...r)=>Be(r,s)}},je=()=>{let{extend:e}=h();return Object.keys(e).reduce(Ne,{})},$e=e=>{let t=w();return R({...t,props:e}),b()},Le=e=>{let t=w();return R({...t,interactionConfig:e}),b()},Fe=(e=[])=>{let t=w(),n=Array.isArray(e)?e:[e];return R({...t,responses:[...t.responses,...n]}),b()},_e=(e,t)=>{let n=w();return R({...n,historyState:t,path:e,hasPath:!0}),b()},Ge=()=>{let e=w();return R({...e,debug:!0}),b()},Ve=()=>{let{portal:e,portals:t,changeRoute:n,history:s,mount:r,interaction:o}=h(),{Component:i,props:l,responses:c,path:u,hasPath:a,debug:m,historyState:p,interactionConfig:y}=w(),g=i;e&&X(e),t&&Qe(t),a&&s&&(console.warn("wrapito WARNING: history is DEPRECATED. Pass a changeRoute function to the config instead."),console.warn("Read about changeRoute in: https://github.com/mercadona/wrapito#changeRoute"),s.push(u,p)),a&&!s&&n(u),G(c,m);let f=r(K.createElement(g,{...l}));if(o){let k=o.setup?o.setup(o.userLib,y):o.userLib;return{...f,user:k}}return{...f,user:void 0}},X=e=>{if(document.getElementById(e))return;let t=document.createElement("div");t.setAttribute("id",e),t.setAttribute("data-testid",e),document.body.appendChild(t)},Qe=e=>{e.forEach(t=>{X(t)})};var H=require("jest-diff"),S=(e,t)=>{let n=t?.host?`\u{1F32F} Wrapito: ${t?.host}${e} ain't got called`:`\u{1F32F} Wrapito: ${e} ain't got called`;return{pass:!1,message:()=>n}},Z=(e,t,n)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: ${e} is called ${n} times, you expected ${t} times`}),ee=(e,t)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch method does not match, expected ${e} received ${t??"none"}`}),te=(e,t)=>{let n=t.map(s=>(0,H.diff)(e,s)).join(`
14
13
 
15
14
  `);return{pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch body does not match.
16
15
  ${n}`}},ne=(e,t)=>{let n=t.find(s=>e!==s);return{pass:!1,message:()=>`\u{1F32F} Wrapito: Host request does not match, expected ${e} received ${n}`}},se=(e,t)=>{let n=t.map(s=>(0,H.diff)(e,s)).join(`
package/dist/index.mjs CHANGED
@@ -3,14 +3,13 @@ ${d.white.bold.bgRed("wrapito")} ${d.redBright.bold("cannot find any mock matchi
3
3
  ${d.greenBright(`URL: ${e.url}`)}
4
4
  ${d.greenBright(`METHOD: ${e.method?.toLowerCase()}`)}
5
5
  ${d.greenBright(`REQUEST BODY: ${e._bodyInit}`)}
6
- `),B=async(e,t,n)=>{let s=e.find(H(t));if(!s)return n&&de(t),N();let{multipleResponses:r}=s;if(!r)return S(s);let o=r.find(i=>!i.hasBeenReturned);if(!o){n&&he(s);return}return o.hasBeenReturned=!0,S(o)},j=(e=[],t=!1)=>{global.window.fetch.mockImplementation((s,r)=>{if(typeof s=="string"){let i=new Request(s,r);return B(e,i,t)}return B(e,s,t)})},he=e=>{let t=`\u{1F32F} Wrapito: Missing response in the multipleResponses
7
- array for path ${e.path} and method ${e.method}.`,n=d.greenBright(t);console.warn(n)},$=e=>{global.window.fetch.mockImplementation((t,n)=>{let s=typeof t=="string"?t:t.url,r=n?.method||(typeof t!="string"?t.method:"GET");return console.warn(`
6
+ `),B=async(e,t,n)=>{let s=e.find(H(t));if(!s)return n&&de(t),N();let{multipleResponses:r}=s;if(!r)return S(s);let o=r.find(i=>!i.hasBeenReturned);if(!o){n&&he(s);return}return o.hasBeenReturned=!0,S(o)},j=(e=[],t=!1)=>{global.window.fetch.mockImplementation((s,r)=>{if(typeof s=="string"){let i=new Request(s,r);return B(e,i,t)}return B(e,s,t)})},he=e=>{let t=`\u{1F32F} Wrapito: Missing response in the multipleResponses array for path ${e.path} and method ${e.method}.`,n=d.greenBright(t);console.warn(n)},$=e=>{let t=global.window.fetch.getMockImplementation();global.window.fetch.mockImplementation((n,s)=>{let r=typeof n=="string"?n:n.url,o=s?.method||(typeof n!="string"?n.method:"GET");return console.warn(`
8
7
  ${d.white.bold.bgYellow(" \u{1F32F} wrapito ")}
9
8
  ${d.yellowBright.bold("\u26A0\uFE0F pending request detected after test finished:")}
10
- ${d.greenBright(`URL: ${s}`)}
11
- ${d.greenBright(`METHOD: ${r?.toLowerCase()}`)}
9
+ ${d.greenBright(`URL: ${r}`)}
10
+ ${d.greenBright(`METHOD: ${o?.toLowerCase()}`)}
12
11
  ${e?` ${d.greenBright(`TEST: ${e}`)}
13
- `:""}`),N()})};var W,R=e=>{W={...W,...e}},w=()=>({...W});function T(e,t){if(!e)throw new Error(t)}function I(e,t){return typeof t===e}function ge(e){return e instanceof Promise}function A(e,t,n){Object.defineProperty(e,t,n)}function x(e,t,n){Object.defineProperty(e,t,{value:n})}var M=Symbol.for("tinyspy:spy"),fe=new Set,ye=e=>{e.called=!1,e.callCount=0,e.calls=[],e.results=[],e.next=[]},Re=e=>(A(e,M,{value:{reset:()=>ye(e[M])}}),e[M]),E=e=>e[M]||Re(e);function we(e){T(I("function",e)||I("undefined",e),"cannot spy on a non-function value");let t=function(...s){let r=E(t);r.called=!0,r.callCount++,r.calls.push(s);let o=r.next.shift();if(o){r.results.push(o);let[u,a]=o;if(u==="ok")return a;throw a}let i,l="ok";if(r.impl)try{new.target?i=Reflect.construct(r.impl,s,new.target):i=r.impl.apply(this,s),l="ok"}catch(u){throw i=u,l="error",r.results.push([l,u]),u}let c=[l,i];if(ge(i)){let u=i.then(a=>c[1]=a).catch(a=>{throw c[0]="error",c[1]=a,a});Object.assign(u,i),i=u}return r.results.push(c),i};x(t,"_isMockFunction",!0),x(t,"length",e?e.length:0),x(t,"name",e&&e.name||"spy");let n=E(t);return n.reset(),n.impl=e,t}var L=(e,t)=>Object.getOwnPropertyDescriptor(e,t),F=(e,t)=>{t!=null&&typeof t=="function"&&t.prototype!=null&&Object.setPrototypeOf(e.prototype,t.prototype)};function _(e,t,n){T(!I("undefined",e),"spyOn could not find an object to spy upon"),T(I("object",e)||I("function",e),"cannot spyOn on a primitive value");let[s,r]=(()=>{if(!I("object",t))return[t,"value"];if("getter"in t&&"setter"in t)throw new Error("cannot spy on both getter and setter");if("getter"in t)return[t.getter,"get"];if("setter"in t)return[t.setter,"set"];throw new Error("specify getter or setter to spy on")})(),o=L(e,s),i=Object.getPrototypeOf(e),l=i&&L(i,s),c=o||l;T(c||s in e,`${String(s)} does not exist`);let u=!1;r==="value"&&c&&!c.value&&c.get&&(r="get",u=!0,n=c.get());let a;c?a=c[r]:r!=="value"?a=()=>e[s]:a=e[s],n||(n=a);let m=we(n);r==="value"&&F(m,a);let p=f=>{let{value:k,...P}=c||{configurable:!0,writable:!0};r!=="value"&&delete P.writable,P[r]=f,A(e,s,P)},y=()=>c?A(e,s,c):p(a),g=m[M];return x(g,"restore",y),x(g,"getOriginal",()=>u?a():a),x(g,"willCall",f=>(g.impl=f,m)),p(u?()=>(F(m,n),m):m),fe.add(m),m}var Ie=new Set,xe=0;function ke(e){let t=e,n,s=[],r=[],o=E(e),i={get calls(){return o.calls},get instances(){return s},get invocationCallOrder(){return r},get results(){return o.results.map(([p,y])=>({type:p==="error"?"throw":"return",value:y}))},get lastCall(){return o.calls[o.calls.length-1]}},l=[],c=!1;function u(...p){return s.push(this),r.push(++xe),(c?n:l.shift()||n||o.getOriginal()||(()=>{})).apply(this,p)}let a=t.name;t.getMockName=()=>a||"vi.fn()",t.mockName=p=>(a=p,t),t.mockClear=()=>(o.reset(),s=[],r=[],t),t.mockReset=()=>(t.mockClear(),n=()=>{},l=[],t),t.mockRestore=()=>(t.mockReset(),o.restore(),n=void 0,t),t.getMockImplementation=()=>n,t.mockImplementation=p=>(n=p,o.willCall(u),t),t.mockImplementationOnce=p=>(l.push(p),t);function m(p,y){let g=n;n=p,o.willCall(u),c=!0;let f=()=>{n=g,c=!1},k=y();return k instanceof Promise?k.then(()=>(f(),t)):(f(),t)}return t.withImplementation=m,t.mockReturnThis=()=>t.mockImplementation(function(){return this}),t.mockReturnValue=p=>t.mockImplementation(()=>p),t.mockReturnValueOnce=p=>t.mockImplementationOnce(()=>p),t.mockResolvedValue=p=>t.mockImplementation(()=>Promise.resolve(p)),t.mockResolvedValueOnce=p=>t.mockImplementationOnce(()=>Promise.resolve(p)),t.mockRejectedValue=p=>t.mockImplementation(()=>Promise.reject(p)),t.mockRejectedValueOnce=p=>t.mockImplementationOnce(()=>Promise.reject(p)),Object.defineProperty(t,"mock",{get:()=>i}),o.willCall(u),Ie.add(t),t}var G=e=>ke(_({spy:e||(()=>{})},"spy"));beforeEach(()=>{global.fetch=G()});afterEach(()=>{let{warnOnPendingRequests:e}=h();if(e){let t=expect.getState?.()?.currentTestName;$(t)}});var nt=e=>(R({Component:e,responses:[],props:{},path:"",hasPath:!1,interactionConfig:void 0,debug:process.env.npm_config_debugRequests==="true"}),b()),b=()=>{let e=Ee();return{withProps:qe,withNetwork:Ue,withInteraction:Pe,atPath:We,debugRequests:Ae,mount:ve,...e}},Me=e=>{let t=w(),n=[...t.responses,...e];R({...t,responses:n})},Oe=(e,t)=>(t({addResponses:Me},e),b()),Te=(e,t)=>{let{extend:n}=h(),s=n[t];return{...e,[t]:(...r)=>Oe(r,s)}},Ee=()=>{let{extend:e}=h();return Object.keys(e).reduce(Te,{})},qe=e=>{let t=w();return R({...t,props:e}),b()},Pe=e=>{let t=w();return R({...t,interactionConfig:e}),b()},Ue=(e=[])=>{let t=w(),n=Array.isArray(e)?e:[e];return R({...t,responses:[...t.responses,...n]}),b()},We=(e,t)=>{let n=w();return R({...n,historyState:t,path:e,hasPath:!0}),b()},Ae=()=>{let e=w();return R({...e,debug:!0}),b()},ve=()=>{let{portal:e,portals:t,changeRoute:n,history:s,mount:r,interaction:o}=h(),{Component:i,props:l,responses:c,path:u,hasPath:a,debug:m,historyState:p,interactionConfig:y}=w(),g=i;e&&Q(e),t&&Ce(t),a&&s&&(console.warn("wrapito WARNING: history is DEPRECATED. Pass a changeRoute function to the config instead."),console.warn("Read about changeRoute in: https://github.com/mercadona/wrapito#changeRoute"),s.push(u,p)),a&&!s&&n(u),j(c,m);let f=r(V.createElement(g,{...l}));if(o){let k=o.setup?o.setup(o.userLib,y):o.userLib;return{...f,user:k}}return{...f,user:void 0}},Q=e=>{if(document.getElementById(e))return;let t=document.createElement("div");t.setAttribute("id",e),t.setAttribute("data-testid",e),document.body.appendChild(t)},Ce=e=>{e.forEach(t=>{Q(t)})};import{diff as J}from"jest-diff";var v=(e,t)=>{let n=t?.host?`\u{1F32F} Wrapito: ${t?.host}${e} ain't got called`:`\u{1F32F} Wrapito: ${e} ain't got called`;return{pass:!1,message:()=>n}},Y=(e,t,n)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: ${e} is called ${n} times, you expected ${t} times`}),z=(e,t)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch method does not match, expected ${e} received ${t??"none"}`}),K=(e,t)=>{let n=t.map(s=>J(e,s)).join(`
12
+ `:""}`),t?t(n,s):N()})};var W,R=e=>{W={...W,...e}},w=()=>({...W});function T(e,t){if(!e)throw new Error(t)}function I(e,t){return typeof t===e}function ge(e){return e instanceof Promise}function A(e,t,n){Object.defineProperty(e,t,n)}function x(e,t,n){Object.defineProperty(e,t,{value:n})}var M=Symbol.for("tinyspy:spy"),fe=new Set,ye=e=>{e.called=!1,e.callCount=0,e.calls=[],e.results=[],e.next=[]},Re=e=>(A(e,M,{value:{reset:()=>ye(e[M])}}),e[M]),E=e=>e[M]||Re(e);function we(e){T(I("function",e)||I("undefined",e),"cannot spy on a non-function value");let t=function(...s){let r=E(t);r.called=!0,r.callCount++,r.calls.push(s);let o=r.next.shift();if(o){r.results.push(o);let[u,a]=o;if(u==="ok")return a;throw a}let i,l="ok";if(r.impl)try{new.target?i=Reflect.construct(r.impl,s,new.target):i=r.impl.apply(this,s),l="ok"}catch(u){throw i=u,l="error",r.results.push([l,u]),u}let c=[l,i];if(ge(i)){let u=i.then(a=>c[1]=a).catch(a=>{throw c[0]="error",c[1]=a,a});Object.assign(u,i),i=u}return r.results.push(c),i};x(t,"_isMockFunction",!0),x(t,"length",e?e.length:0),x(t,"name",e&&e.name||"spy");let n=E(t);return n.reset(),n.impl=e,t}var L=(e,t)=>Object.getOwnPropertyDescriptor(e,t),F=(e,t)=>{t!=null&&typeof t=="function"&&t.prototype!=null&&Object.setPrototypeOf(e.prototype,t.prototype)};function _(e,t,n){T(!I("undefined",e),"spyOn could not find an object to spy upon"),T(I("object",e)||I("function",e),"cannot spyOn on a primitive value");let[s,r]=(()=>{if(!I("object",t))return[t,"value"];if("getter"in t&&"setter"in t)throw new Error("cannot spy on both getter and setter");if("getter"in t)return[t.getter,"get"];if("setter"in t)return[t.setter,"set"];throw new Error("specify getter or setter to spy on")})(),o=L(e,s),i=Object.getPrototypeOf(e),l=i&&L(i,s),c=o||l;T(c||s in e,`${String(s)} does not exist`);let u=!1;r==="value"&&c&&!c.value&&c.get&&(r="get",u=!0,n=c.get());let a;c?a=c[r]:r!=="value"?a=()=>e[s]:a=e[s],n||(n=a);let m=we(n);r==="value"&&F(m,a);let p=f=>{let{value:k,...P}=c||{configurable:!0,writable:!0};r!=="value"&&delete P.writable,P[r]=f,A(e,s,P)},y=()=>c?A(e,s,c):p(a),g=m[M];return x(g,"restore",y),x(g,"getOriginal",()=>u?a():a),x(g,"willCall",f=>(g.impl=f,m)),p(u?()=>(F(m,n),m):m),fe.add(m),m}var Ie=new Set,xe=0;function ke(e){let t=e,n,s=[],r=[],o=E(e),i={get calls(){return o.calls},get instances(){return s},get invocationCallOrder(){return r},get results(){return o.results.map(([p,y])=>({type:p==="error"?"throw":"return",value:y}))},get lastCall(){return o.calls[o.calls.length-1]}},l=[],c=!1;function u(...p){return s.push(this),r.push(++xe),(c?n:l.shift()||n||o.getOriginal()||(()=>{})).apply(this,p)}let a=t.name;t.getMockName=()=>a||"vi.fn()",t.mockName=p=>(a=p,t),t.mockClear=()=>(o.reset(),s=[],r=[],t),t.mockReset=()=>(t.mockClear(),n=()=>{},l=[],t),t.mockRestore=()=>(t.mockReset(),o.restore(),n=void 0,t),t.getMockImplementation=()=>n,t.mockImplementation=p=>(n=p,o.willCall(u),t),t.mockImplementationOnce=p=>(l.push(p),t);function m(p,y){let g=n;n=p,o.willCall(u),c=!0;let f=()=>{n=g,c=!1},k=y();return k instanceof Promise?k.then(()=>(f(),t)):(f(),t)}return t.withImplementation=m,t.mockReturnThis=()=>t.mockImplementation(function(){return this}),t.mockReturnValue=p=>t.mockImplementation(()=>p),t.mockReturnValueOnce=p=>t.mockImplementationOnce(()=>p),t.mockResolvedValue=p=>t.mockImplementation(()=>Promise.resolve(p)),t.mockResolvedValueOnce=p=>t.mockImplementationOnce(()=>Promise.resolve(p)),t.mockRejectedValue=p=>t.mockImplementation(()=>Promise.reject(p)),t.mockRejectedValueOnce=p=>t.mockImplementationOnce(()=>Promise.reject(p)),Object.defineProperty(t,"mock",{get:()=>i}),o.willCall(u),Ie.add(t),t}var G=e=>ke(_({spy:e||(()=>{})},"spy"));beforeEach(()=>{global.fetch=G()});afterEach(()=>{let{warnOnPendingRequests:e}=h();if(e){let t=expect.getState?.()?.currentTestName;$(t)}});var nt=e=>(R({Component:e,responses:[],props:{},path:"",hasPath:!1,interactionConfig:void 0,debug:process.env.npm_config_debugRequests==="true"}),b()),b=()=>{let e=Ee();return{withProps:qe,withNetwork:Ue,withInteraction:Pe,atPath:We,debugRequests:Ae,mount:ve,...e}},Me=e=>{let t=w(),n=[...t.responses,...e];R({...t,responses:n})},Oe=(e,t)=>(t({addResponses:Me},e),b()),Te=(e,t)=>{let{extend:n}=h(),s=n[t];return{...e,[t]:(...r)=>Oe(r,s)}},Ee=()=>{let{extend:e}=h();return Object.keys(e).reduce(Te,{})},qe=e=>{let t=w();return R({...t,props:e}),b()},Pe=e=>{let t=w();return R({...t,interactionConfig:e}),b()},Ue=(e=[])=>{let t=w(),n=Array.isArray(e)?e:[e];return R({...t,responses:[...t.responses,...n]}),b()},We=(e,t)=>{let n=w();return R({...n,historyState:t,path:e,hasPath:!0}),b()},Ae=()=>{let e=w();return R({...e,debug:!0}),b()},ve=()=>{let{portal:e,portals:t,changeRoute:n,history:s,mount:r,interaction:o}=h(),{Component:i,props:l,responses:c,path:u,hasPath:a,debug:m,historyState:p,interactionConfig:y}=w(),g=i;e&&Q(e),t&&Ce(t),a&&s&&(console.warn("wrapito WARNING: history is DEPRECATED. Pass a changeRoute function to the config instead."),console.warn("Read about changeRoute in: https://github.com/mercadona/wrapito#changeRoute"),s.push(u,p)),a&&!s&&n(u),j(c,m);let f=r(V.createElement(g,{...l}));if(o){let k=o.setup?o.setup(o.userLib,y):o.userLib;return{...f,user:k}}return{...f,user:void 0}},Q=e=>{if(document.getElementById(e))return;let t=document.createElement("div");t.setAttribute("id",e),t.setAttribute("data-testid",e),document.body.appendChild(t)},Ce=e=>{e.forEach(t=>{Q(t)})};import{diff as J}from"jest-diff";var v=(e,t)=>{let n=t?.host?`\u{1F32F} Wrapito: ${t?.host}${e} ain't got called`:`\u{1F32F} Wrapito: ${e} ain't got called`;return{pass:!1,message:()=>n}},Y=(e,t,n)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: ${e} is called ${n} times, you expected ${t} times`}),z=(e,t)=>({pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch method does not match, expected ${e} received ${t??"none"}`}),K=(e,t)=>{let n=t.map(s=>J(e,s)).join(`
14
13
 
15
14
  `);return{pass:!1,message:()=>`\u{1F32F} Wrapito: Fetch body does not match.
16
15
  ${n}`}},X=(e,t)=>{let n=t.find(s=>e!==s);return{pass:!1,message:()=>`\u{1F32F} Wrapito: Host request does not match, expected ${e} received ${n}`}},Z=(e,t)=>{let n=t.map(s=>J(e,s)).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrapito",
3
- "version": "13.3.1-beta6",
3
+ "version": "13.3.1",
4
4
  "packageManager": "npm@10.8.2",
5
5
  "description": "🌯 🌯 Wrap you tests so that you can test both behaviour and components with less effort.",
6
6
  "type": "module",