diff --git a/index.test.js b/index.test.js index 5a27d51..8fca5e2 100644 --- a/index.test.js +++ b/index.test.js @@ -1,8 +1,7 @@ const { on, once, emit, unsubscribeOf } = require("./index"); -function expect(task, condition, desc) { - task() - if (condition()) console.log('✅', desc); +const expect = (process, desc) => { + if (process()) console.log('✅', desc); else console.log('❌', desc); return expect; } @@ -13,19 +12,19 @@ const DEC = 'DEC'; let refunds; let counter = 0; -const unsubscribeINC = on(INC, function () { +const unsubscribeINC = on(INC, () => { counter++ return counter; }); -function incremental() { +const incremental = () => { counter++ return counter; } on(INC, incremental); -once(DEC, function () { +once(DEC, () => { counter--; return counter; }); @@ -46,84 +45,44 @@ once(DEC, function () { */ -expect( - function () { +expect + (() => { // nothing - }, - function () { return counter === 0 - }, - 'S1' -)( - function () { + }, 'S1') + (() => { refunds = emit(INC) - }, - function () { return counter === 2 - }, - 'S2' -)( - function () { + }, 'S2') + (() => { // nothing - }, - function () { return refunds[0] === 1 && refunds[1] === 2 && refunds.length === 2 - }, - 'S2.1' -)( - function () { + }, 'S2.1') + (() => { emit(DEC) - }, - function () { return counter === 1 - }, - 'S3' -)( - function () { + }, 'S3') + (() => { unsubscribeINC() - }, - function () { return counter === 1 - }, - 'S4' -)( - function () { + }, 'S4') + (() => { emit(INC) - }, - function () { return counter === 2 - }, - 'S5' -)( - function () { + }, 'S5') + (() => { emit(DEC) - }, - function () { return counter === 2 - }, - 'S6' -)( - function () { + }, 'S6') + (() => { unsubscribeOf(INC, incremental) - }, - function () { return counter === 2 - }, - 'S7' -)( - function () { + }, 'S7') + (() => { refunds = emit(INC) - }, - function () { return counter === 2 - }, - 'S8' -)( - function () { + }, 'S8') + (() => { // nothing - }, - function () { return refunds.length === 0 - }, - 'S8.1' -); \ No newline at end of file + }, 'S8.1'); \ No newline at end of file