UNPKG

@rxx/worker

Version:

React MVI micro framework.

84 lines (83 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); require("core-js"); var intent_1 = require("../intent"); var power_assert_1 = tslib_1.__importDefault(require("power-assert")); var assert_1 = tslib_1.__importDefault(require("assert")); describe('intent.ts', function () { describe('Intent', function () { describe('#push()', function () { it('should dispatch event.', function () { var intent = new intent_1.Intent(); intent.setState(null); var fired; var disp = intent.response.for('test').subscribe(function (v) { fired = v; }); intent.push('test', true); assert_1.default.deepStrictEqual(fired, { data: true, state: null }); disp.unsubscribe(); }); }); describe('#subscribeEvent()', function () { it('should dispatch subscriber.', function () { var intent = new intent_1.Intent(); var called = false; intent.subscribeEvent(function () { called = true; }); intent.response.for('test').subscribe(function () { }); intent.push('test'); power_assert_1.default.ok(called); }); it('should dispatch if RETRY dispatched.', function () { var intent = new intent_1.Intent(); var results = []; intent.subscribeEvent(function (type) { results.push(type); }); intent.response.for('test-gp').subscribe(function () { }); intent.response.for('test-p').subscribe(function () { }); intent.response.for('test').subscribe(function () { }); intent.response.for('test-c').subscribe(function () { }); intent.response.for('test-gc').subscribe(function () { }); intent.push('test-gp'); intent.push('test-p'); intent.push('test'); intent.push('test-c'); intent.push('test-gc'); intent.push('RETRY', 'test-gp'); intent.push('RETRY', 'test-p'); intent.push('RETRY', 'test'); intent.push('RETRY', 'test-c'); intent.push('RETRY', 'test-gc'); assert_1.default.deepStrictEqual(results, [ 'test-gp', 'test-p', 'test', 'test-c', 'test-gc', 'test-gp', 'test-p', 'test', 'test-c', 'test-gc', ]); }); }); describe('#callback()', function () { it('should return event dispatching callback.', function () { var intent = new intent_1.Intent(); intent.setState(null); var fired; var disp = intent.response.for('test').subscribe(function (v) { fired = v; }); intent.callback('test', true)(); assert_1.default.deepStrictEqual(fired, { data: true, state: null }); disp.unsubscribe(); }); }); }); });