@rxx/testing
Version:
Testing module for rxx.
80 lines (79 loc) • 2.69 kB
JavaScript
;
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
require("core-js");
var core_1 = require("@rxx/core");
var operators_1 = require("rxjs/operators");
var prepare_1 = require("../prepare");
var chai_1 = require("chai");
var AIntent = (function () {
function AIntent() {
}
Object.defineProperty(AIntent.prototype, "test", {
get: function () {
return this.intent.for('a::a').pipe(operators_1.share());
},
enumerable: true,
configurable: true
});
AIntent = tslib_1.__decorate([
core_1.intent
], AIntent);
return AIntent;
}());
var AStore = (function () {
function AStore() {
}
AStore.prototype.initialize = function () {
return {
view: {
test: (this.intent || this.aIntent).test.pipe(operators_1.mapTo(1), operators_1.startWith(0)),
},
};
};
AStore = tslib_1.__decorate([
core_1.store
], AStore);
return AStore;
}());
function factory(observable, initialState) {
return {
view: observable.pipe(operators_1.filter(function (args) { return args.type === 'test'; }), operators_1.mapTo(1)),
};
}
describe('prepare()', function () {
it('should prepare store and mocked intent', function (done) {
var _a = prepare_1.prepareTest(AIntent, AStore), store = _a.store, mock = _a.mock;
var test = store.initialize().view.test;
test.pipe(operators_1.skip(1)).subscribe(function (v) {
chai_1.expect(v).to.be.eq(1);
done();
});
mock.send('test');
});
it('should prepare store and multi mocked intent', function (done) {
var _a = prepare_1.prepareTest({ aIntent: AIntent }, AStore, {
multiIntent: true,
}), store = _a.store, mock = _a.mock;
var test = store.initialize().view.test;
test.pipe(operators_1.skip(1)).subscribe(function (v) {
chai_1.expect(v).to.be.eq(1);
done();
});
mock.aIntent.send('test');
});
});
describe('interrupt', function () {
it('should prepare store mock', function (done) {
var _a = prepare_1.initAppTester(factory, 1), input = _a.input, output = _a.output;
var sub = prepare_1.safeSubscribe(output.view, function (state) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
chai_1.expect(state).to.be.eq(1);
sub.unsubscribe();
return [2];
});
}); }, done);
input('test');
});
});