UNPKG

vitest-marbles

Version:

Marble testing helpers library for RxJs and Jest

2 lines 7.65 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("rxjs"),require("rxjs/testing")):"function"==typeof define&&define.amd?define("VitestMarbles",["rxjs","rxjs/testing"],e):"object"==typeof exports?exports.VitestMarbles=e(require("rxjs"),require("rxjs/testing")):t.VitestMarbles=e(t.rxjs,t["rxjs/testing"])}("undefined"!=typeof self?self:this,((t,e)=>(()=>{"use strict";var n={832:e=>{e.exports=t},422:t=>{t.exports=e}},r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var i=r[t]={exports:{}};return n[t](i,i.exports,o),i.exports}o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{o.r(i),o.d(i,{Scheduler:()=>b,cold:()=>x,hot:()=>y,time:()=>S});var t,e=o(832),n=o(422);!function(t){t.Completion="|",t.Error="#",t.TimeFrame="-",t.Subscription="^",t.Unsubscription="!",t.GroupStart="(",t.GroupEnd=")"}(t||(t={}));var r=function(){function t(t){this.start=t,this.marbles=""}return Object.defineProperty(t.prototype,"end",{get:function(){return this.start+this.marbles.length},enumerable:!1,configurable:!0}),t}(),s={},c={N:s,C:t.Completion,E:t.Error},u=function(){function e(){}return e.marblize=function(n){for(var r=e.getNotificationEvents(n),o="",i=0,s=0;i<r.length;s=r[i].end,i++)o="".concat(o).concat(t.TimeFrame.repeat(r[i].start-s)+r[i].marbles);return o},e.marblizeSubscriptions=function(e){var n=this;return e.map((function(e){return n.marblizeLogEntry(e.subscribedFrame/10,t.Subscription)+n.marblizeLogEntry((e.unsubscribedFrame-e.subscribedFrame)/10-1,t.Unsubscription)}))},e.marblizeLogEntry=function(e,n){return e!==1/0?t.TimeFrame.repeat(e)+n:""},e.getNotificationEvents=function(t){var n=t.reduce((function(t,n){return t[n.frame]||(t[n.frame]=new r(n.frame/10)),t[n.frame].marbles+=e.extractMarble(n),t}),{}),o=Object.keys(n).map((function(t){return n[t]}));return e.encloseGroupEvents(o),o},e.extractMarble=function(t){var e=c[t.notification.kind];return e===s&&(e=t.notification.value),e},e.encloseGroupEvents=function(e){e.forEach((function(e){e.marbles.length>1&&(e.marbles="".concat(t.GroupStart).concat(e.marbles).concat(t.GroupEnd))}))},e}();function a(t){var e=t.notification.value;return"string"==typeof e&&1===e.length||void 0!==e&&1===JSON.stringify(e).length}var l={toBeNotifications:function(t,e){var n=this,r=t,o=e;(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return t.every((function(t){return t.filter((function(t){return"N"===t.notification.kind})).every(a)}))})(t,e)&&(r=u.marblize(t),o=u.marblize(e));var i=this.equals(r,o);return{message:i?function(){return n.utils.matcherHint(".not.toBeNotifications")+"\n\nExpected notifications to not be:\n"+" ".concat(n.utils.printExpected(o),"\n")+"But got:\n"+" ".concat(n.utils.printReceived(r))}:function(){var t=n.utils.diff(o,r,{expand:!0});return n.utils.matcherHint(".toBeNotifications")+"\n\nExpected notifications to be:\n"+" ".concat(n.utils.printExpected(o),"\n")+"But got:\n"+" ".concat(n.utils.printReceived(r))+(t?"\n\nDifference:\n\n".concat(t):"")},pass:i}},toBeSubscriptions:function(t,e){var n=this,r=u.marblizeSubscriptions(t),o=u.marblizeSubscriptions(e),i=function(t,e){if(t.length!==e.length)return!1;for(var n=!0,r=0,o=t;r<o.length;r++){var i=o[r];if(!e.includes(i)){n=!1;break}}return n}(r,o);return{message:i?function(){return n.utils.matcherHint(".not.toHaveSubscriptions")+"\n\nExpected observable to not have the following subscription points:\n"+" ".concat(n.utils.printExpected(o),"\n")+"But got:\n"+" ".concat(n.utils.printReceived(r))}:function(){var t=n.utils.diff(o,r,{expand:!0});return n.utils.matcherHint(".toHaveSubscriptions")+"\n\nExpected observable to have the following subscription points:\n"+" ".concat(n.utils.printExpected(o),"\n")+"But got:\n"+" ".concat(n.utils.printReceived(r))+(t?"\n\nDifference:\n\n".concat(t):"")},pass:i}},toHaveEmptySubscriptions:function(t){var e,n=this,r=!(t&&t.length>0);return t&&t.length>0&&(e=u.marblizeSubscriptions(t)),{message:r?function(){return n.utils.matcherHint(".not.toHaveNoSubscriptions")+"\n\nExpected observable to have at least one subscription point, but got nothing"+n.utils.printReceived("")}:function(){return n.utils.matcherHint(".toHaveNoSubscriptions")+"\n\nExpected observable to have no subscription points\nBut got:\n"+" ".concat(n.utils.printReceived(e),"\n\n")},pass:r}}};function f(t,e){e&&(function(t,e){return 0===e.length&&0!==t.length&&void 0!==t[0].subscribedFrame}(t,e)?expect(t).toHaveEmptySubscriptions():function(t,e){return 0===t.length&&0===e.length||0!==e.length&&void 0!==e[0].subscribedFrame}(t,e)?expect(t).toBeSubscriptions(e):expect(t).toBeNotifications(e))}expect.extend(l);var p,b=function(){function t(){}return t.init=function(){t.instance=new n.TestScheduler(f)},t.get=function(){if(t.instance)return t.instance;throw new Error("Scheduler is not initialized")},t.reset=function(){t.instance=null},t.materializeInnerObservable=function(e,n){return t.get().materializeInnerObservable(e,n)},t}(),v=(p=function(t,e){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},p(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),g=function(t){function e(e,n,r){var o=t.call(this)||this;return o.marbles=e,o.values=n,o.error=r,o.source=b.get().createColdObservable(e,n,r),o}return v(e,t),e.prototype.getSubscriptions=function(){return this.source.subscriptions},e}(e.Observable),h=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),d=function(t){function e(e,n,r){var o=t.call(this)||this;return o.marbles=e,o.values=n,o.error=r,o.source=b.get().createHotObservable(e,n,r),o}return h(e,t),e.prototype.getSubscriptions=function(){return this.source.subscriptions},e}(e.Observable);function m(t){return t.replace(/^[ ]+/,"")}function y(t,e,n){return new d(m(t),e,n)}function x(t,e,n){return new g(m(t),e,n)}function S(t){return b.get().createTime(m(t))}var E={message:function(){return""},pass:!0};expect.extend({toHaveSubscriptions:function(t,e){var n=Array.isArray(e)?e.map(m):m(e);return b.get().expectSubscriptions(t.getSubscriptions()).toBe(n),E},toHaveNoSubscriptions:function(t){return b.get().expectSubscriptions(t.getSubscriptions()).toBe([]),E},toBeObservable:function(t,e){return b.get().expectObservable(t).toBe(e.marbles,e.values,e.error),E},toBeMarble:function(t,e){return b.get().expectObservable(t).toBe(m(e)),E},toSatisfyOnFlush:function(t,e){b.get().expectObservable(t);var n=b.get().flushTests;return n[n.length-1].ready=!0,O.push(e),E}});var O=[];beforeEach((function(){b.init(),O=[]})),afterEach((function(){for(b.get().flush();O.length>0;)O.shift()();b.reset()}))})(),i})())); //# sourceMappingURL=vitest-marbles.min.js.map