UNPKG

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

94 lines (80 loc) 2.8 kB
import Bunyan from 'bunyan'; const log = Bunyan.createLogger({name: "ActionTest"}); 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 action 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 action to the Minion class`, ()=>{ let bonky = 0; const onSetMethod =(minion, value)=>bonky = value; classOMat.field('onSetTest').action().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(1000); expect(minion._params.onSetTest).to.equal(1000); expect(bonky).to.equal(1000); } ); it(`should be able to add an onGet action to the Minion class`, ()=>{ let bonky =0; const onGetMethod =(minion, value)=>bonky = value; classOMat.field('onGetTest').action().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(1000); expect(minion._params.onGetTest).to.equal(1000); expect(bonky).to.equal(1000); } ); it(`should be able to add an onGet and onSet action with the same method to the same field`, ()=>{ let bonky = 0; const onGetSetMethod =(minion, value)=>bonky+=value; classOMat = new ClassOMat(); classOMat.BaseClass(BaseMinion) .field('onGetSet') .action().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(1000); expect(bonky).to.equal(1000); expect(minion.onGetSet()).to.equal(1000); expect(bonky).to.equal(2000); } ); } );