class-o-mat
Version:
ALPHA VERSION ONLY: class-o-mats will help to create getter-setter functionality with validations that can be attached to a container class for easier coding. Some basic validations are included. class-o-mats also has the ability to store params as bloc
86 lines (73 loc) • 2.56 kB
JavaScript
import Bunyan from 'bunyan';
const log = Bunyan.createLogger({name: "ReducerTest"});
import 'mocha';
import { expect } from 'chai';
import { NONE,
TEST_CLASS,
CLASS_O_MAT,
FIELD,
CHILD_ADDER,
COPY,
STACK,
QUEUE
} from '../src/constants';
import ClassOMat from '../src/class-o-mat';
describe(`Test of the basic reducer functions.`,
()=>{
class BaseMinion {
TYPE = 'TEST';
}
var classOMat;
var minion;
it(`create a basic classOMat created Minion class and instance`,
()=>{
classOMat = new ClassOMat();
classOMat.BaseClass(BaseMinion)
.$();
minion = new (classOMat.$())();
expect(classOMat.TYPE).to.equal(CLASS_O_MAT);
expect(minion.TYPE).to.equal('TEST');
}
);
it(`should be able to add an onSet reducer to the Minion class`,
()=>{
const onSetMethod =(value)=>value + 100;
classOMat.field('onSetTest').reducer().onSet(true).method(onSetMethod).$()
minion = new (classOMat.$())();
minion.onSetTest(1000);
expect(minion.TYPE).to.equal('TEST');
expect(typeof minion.onSetTest).to.equal('function');
expect(minion.onSetTest()).to.equal(1100);
expect(minion._params.onSetTest).to.equal(1100);
}
);
it(`should be able to add an onGet reducer to the Minion class`,
()=>{
const onGetMethod =(value)=>value - 100;
classOMat.field('onGetTest').reducer().onSet(true).method(onGetMethod).$()
minion = new (classOMat.$())();
minion.onGetTest(1000);
expect(minion.TYPE).to.equal('TEST');
expect(typeof minion.onGetTest).to.equal('function');
expect(minion.onGetTest()).to.equal(900);
expect(minion._params.onGetTest).to.equal(900);
}
);
it(`should be able to add an onGet and onSet reducer
with the same method to the same field`,
()=>{
const onGetSetMethod =(value)=>value + 100;
classOMat = new ClassOMat();
classOMat.BaseClass(BaseMinion)
.field('onGetSet')
.reducer().onSet(true).onGet(true).method(onGetSetMethod).$();
minion = new (classOMat.$())();
minion.onGetSet(1000);
expect(minion.TYPE).to.equal('TEST');
expect(typeof minion.onGetSet).to.equal('function');
expect(minion._params.onGetSet).to.equal(1100);
expect(minion.onGetSet()).to.equal(1200);
}
);
}
);