UNPKG

lazy-aggregator

Version:
75 lines (60 loc) 1.72 kB
const expect = require('chai').expect; const tested = require('./index'); const {add, del} = require('./index'); const configs = { 1: 123, array: [1, 2, 3, 4, 5], mul: (a) => a * a }; describe('lazy-aggregator', function () { function fn(a, b) { switch (true) { case typeof b === 'number': { return b * 2; } case typeof b === 'function': { return b; } case Array.isArray(b): { return {array: b, string: b.join('_')}; } default: { return b; } } }; const aggregation = new tested(configs, fn); it('tested', async function () { expect(aggregation instanceof tested).to.equal(true); }); it('get', async function () { expect(aggregation['1']).to.equal(246); }); it('use', async function () { expect(aggregation['mul'](3)).to.equal(9); }); it('use instance', async function () { expect(aggregation['array'].array instanceof Array).to.equal(true); }); it('add', async function () { aggregation[add]('added', {value: 'added'}); expect(aggregation.added.value).to.equal('added'); }); it('del', async function () { aggregation[add]('deleted', {value: 'deleted'}); expect(aggregation.deleted.value).to.equal('deleted'); aggregation[del]('del'); expect(aggregation.del).to.equal(undefined); }); it('replace', async function () { aggregation[add]('replaced', {value: 'replace1'}); expect(aggregation.replaced.value).to.equal('replace1'); aggregation.replaced = {value: 'replace2'}; expect(aggregation.replaced.value).to.equal('replace2'); }); it('no args', async function () { const aggregation = new tested(); aggregation[add]('added', {value: 'added'}); expect(aggregation.added.value).to.equal('added'); }); });