Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
behnammodi committed Mar 13, 2020
1 parent 7952957 commit 1e5a90f
Showing 1 changed file with 26 additions and 67 deletions.
93 changes: 26 additions & 67 deletions 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;
}
Expand All @@ -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;
});
Expand All @@ -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'
);
}, 'S8.1');

0 comments on commit 1e5a90f

Please sign in to comment.