@hirez_io/observer-spy
Version:
A simple little class that helps making Observable testing a breeze
37 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetAutoUnsubscribe = exports.getGlobalSubscribersLength = exports.queueForAutoUnsubscribe = exports.autoUnsubscribe = void 0;
var isAutoUnsubscribeSet = false;
var subscribers = [];
function autoUnsubscribe() {
/* istanbul ignore if */
if (!afterEach) {
throw new Error("\n autoUnsubscribe only works with frameworks that have an \"afterEach\" function,\n like Jasmine or Jest.\n If you want to add support to more frameworks please submit a PR :)\n ");
}
isAutoUnsubscribeSet = true;
afterEach(function () {
unsubscribeFromAll();
});
}
exports.autoUnsubscribe = autoUnsubscribe;
function queueForAutoUnsubscribe(subscription) {
if (isAutoUnsubscribeSet) {
subscribers.push(subscription);
}
}
exports.queueForAutoUnsubscribe = queueForAutoUnsubscribe;
function getGlobalSubscribersLength() {
return subscribers.length;
}
exports.getGlobalSubscribersLength = getGlobalSubscribersLength;
function resetAutoUnsubscribe() {
isAutoUnsubscribeSet = false;
}
exports.resetAutoUnsubscribe = resetAutoUnsubscribe;
function unsubscribeFromAll() {
subscribers.forEach(function (sub) {
sub.unsubscribe();
});
subscribers = [];
}
//# sourceMappingURL=auto-unsubscribe.js.map