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
80 lines (63 loc) • 2.15 kB
JavaScript
import Bunyan from 'bunyan';
const log = Bunyan.createLogger({name: "NamedChildrenTest"});
import 'mocha';
import { expect } from 'chai';
import { NONE,
TEST_CLASS,
CLASS_O_MAT,
FIELD_O_MAT,
RADIO_O_MAT,
} from '../src/constants';
import ClassOMat from '../src/class-o-mat';
describe(`Test of named children`,
()=> {
class TestClass {
TYPE = 'TEST';
}
class ChildClass {
TYPE = 'CHILD';
}
var classOMat;
var childOMat;
var testClass;
it(`create a basic classOMat created class`,
()=>{
classOMat = new ClassOMat('classOMat');
classOMat.BaseClass(TestClass)
.$();
testClass = new (classOMat.$())();
expect(classOMat.TYPE).to.equal(CLASS_O_MAT);
expect(testClass.TYPE).to.equal('TEST');
}
);
it(`create an childOMat and add it with the named children option.`,
()=>{
let children;
childOMat = new ClassOMat('childOMat');
childOMat.BaseClass(ChildClass)
.field('id');
classOMat.addChild(childOMat)
.accessChildAs('children')
.namedChildren(true)
.as$('addChild');
const minion = new (classOMat.$())();
expect(minion.TYPE).to.equal('TEST');
const childOne = minion.addChild('one').id(0);
expect(childOne.TYPE).to.equal('CHILD');
children = minion.children();
expect(typeof children).to.equal('object');
expect(children.one.TYPE).to.equal('CHILD');
expect(children.one.id()).to.equal(0);
const childTwo = minion.addChild('two').id(1);
expect(childTwo.TYPE).to.equal('CHILD');
children = minion.children();
expect(typeof children).to.equal('object');
expect(Object.keys(children)).to.deep.equal(['one','two']);
expect(children.one.TYPE).to.equal('CHILD');
expect(children.one.id()).to.equal(0);
expect(children.two.TYPE).to.equal('CHILD');
expect(children.two.id()).to.equal(1);
}
);
}
);