jest-marbles
Version:
Marble testing helpers library for RxJs and Jest
2 lines • 7.79 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("rxjs"),require("rxjs/testing")):"function"==typeof define&&define.amd?define("JestMarbles",["rxjs","rxjs/testing"],e):"object"==typeof exports?exports.JestMarbles=e(require("rxjs"),require("rxjs/testing")):t.JestMarbles=e(t.rxjs,t["rxjs/testing"])}("undefined"!=typeof self?self:this,((t,e)=>(()=>{"use strict";var n={418:t=>{t.exports=e},961:e=>{e.exports=t}},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={};o.r(i),o.d(i,{Scheduler:()=>g,cold:()=>j,hot:()=>O,schedule:()=>w,time:()=>_});var c,s=o(961),u=o(418);!function(t){t.Completion="|",t.Error="#",t.TimeFrame="-",t.Subscription="^",t.Unsubscription="!",t.GroupStart="(",t.GroupEnd=")"}(c||(c={}));var a=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}(),l={},f={N:l,C:c.Completion,E:c.Error},p=function(){function t(){}return t.marblize=function(e){for(var n=t.getNotificationEvents(e),r="",o=0,i=0;o<n.length;i=n[o].end,o++)r="".concat(r).concat(c.TimeFrame.repeat(n[o].start-i)+n[o].marbles);return r},t.marblizeSubscriptions=function(t){var e=this;return t.map((function(t){return e.marblizeLogEntry(t.subscribedFrame/10,c.Subscription)+e.marblizeLogEntry((t.unsubscribedFrame-t.subscribedFrame)/10-1,c.Unsubscription)}))},t.marblizeLogEntry=function(t,e){return t!==1/0?c.TimeFrame.repeat(t)+e:""},t.getNotificationEvents=function(e){var n=e.reduce((function(e,n){return e[n.frame]||(e[n.frame]=new a(n.frame/10)),e[n.frame].marbles+=t.extractMarble(n),e}),{}),r=Object.keys(n).map((function(t){return n[t]}));return t.encloseGroupEvents(r),r},t.extractMarble=function(t){var e=f[t.notification.kind];return e===l&&(e=t.notification.value),e},t.encloseGroupEvents=function(t){t.forEach((function(t){t.marbles.length>1&&(t.marbles="".concat(c.GroupStart).concat(t.marbles).concat(c.GroupEnd))}))},t}();function b(t){return t.every((function(t){var e,n=t.notification;return"C"===n.kind||"E"===n.kind&&"error"===n.error||"N"===n.kind&&("string"==typeof(e=n.value)&&1===e.length||void 0!==e&&1===JSON.stringify(e).length)}))}var v={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(b)})(t,e)&&(r=p.marblize(t),o=p.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=p.marblizeSubscriptions(t),o=p.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=p.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 d(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(v);var h,g=function(){function t(){}return t.init=function(){t.instance=new u.TestScheduler(d)},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}(),m=(h=function(t,e){return h=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])},h(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}h(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),y=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=g.get().createColdObservable(e,n,r),o}return m(e,t),e.prototype.getSubscriptions=function(){return this.source.subscriptions},e}(s.Observable),x=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)}}(),S=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=g.get().createHotObservable(e,n,r),o}return x(e,t),e.prototype.getSubscriptions=function(){return this.source.subscriptions},e}(s.Observable);function E(t){return t.replace(/^[ ]+/,"")}function O(t,e,n){return new S(E(t),e,n)}function j(t,e,n){return new y(E(t),e,n)}function _(t){return g.get().createTime(E(t))}function w(t,e){return g.get().schedule(t,e)}var B={message:function(){return""},pass:!0};expect.extend({toHaveSubscriptions:function(t,e){var n=Array.isArray(e)?e.map(E):E(e);return g.get().expectSubscriptions(t.getSubscriptions()).toBe(n),B},toHaveNoSubscriptions:function(t){return g.get().expectSubscriptions(t.getSubscriptions()).toBe([]),B},toBeObservable:function(t,e){return g.get().expectObservable(t).toBe(e.marbles,e.values,e.error),B},toBeMarble:function(t,e){return g.get().expectObservable(t).toBe(E(e)),B},toSatisfyOnFlush:function(t,e){g.get().expectObservable(t);var n=g.get().flushTests;return n[n.length-1].ready=!0,H.push(e),B}});var H=[];return beforeEach((function(){g.init(),H=[]})),afterEach((function(){var t;for(g.get().run((function(){u.TestScheduler.frameTimeFactor=10}));H.length>0;)null===(t=H.shift())||void 0===t||t();g.reset()})),i})()));
//# sourceMappingURL=jest-marbles.min.js.map