Example #1
0
    it('ignores default values that are not defined propertyes', function () {
      const def = new ObjDefine({ name: 'foo', name2: 'bar' });
      const obj = def.create();

      expect(obj).to.not.have.property('name');
      expect(obj).to.not.have.property('name2');
    });
Example #2
0
    it('does not export property to JSON it it\'s undefined or null', function () {
      const def = new ObjDefine();
      def.writ('name');
      expect(flatten(def.create())).to.not.have.property('name');

      def.writ('name', null);
      expect(flatten(def.create())).to.not.have.property('name');
    });
Example #3
0
    it('uses the defaults for property values', function () {
      const def = new ObjDefine({ name: 'bar' });
      def.fact('name');

      const obj = def.create();

      expect(obj).to.have.property('name', 'bar');
    });
Example #4
0
    it('creates object that inherits from the prototype', function () {
      function SomeClass() {}

      const def = new ObjDefine(null, SomeClass.prototype);
      const obj = def.create();

      expect(obj).to.be.a(SomeClass);
    });
Example #5
0
    it('setting a writ value to null prevents it from exporting', function () {
      const def = new ObjDefine();
      def.writ('name', 'foo');

      const obj = def.create();
      expect(flatten(obj)).to.have.property('name', 'foo');

      obj.name = null;
      expect(flatten(obj)).to.not.have.property('name');
    });
Example #6
0
    it('creates writeable properties', function () {
      const def = new ObjDefine();
      def.writ('name', 'foo');

      const obj = def.create();
      expect(obj).to.have.property('name', 'foo');

      obj.name = 'bar';
      expect(obj).to.have.property('name', 'bar');
    });
Example #7
0
    it('creates an immutable field', function () {
      const def = new ObjDefine();
      const val = 'foo';
      const notval = 'bar';
      def.fact('name', val);
      const obj = def.create();


      obj.name = notval; // UPDATE SHOULD BE IGNORED
      expect(obj).to.have.property('name', val);
    });
Example #8
0
    it('creates an immutable field', function () {
      const def = new ObjDefine();
      const val = 'foo';
      const notval = 'bar';
      def.comp('name', val);
      const obj = def.create();

      expect(function () {
        'use strict'; // eslint-disable-line strict

        obj.name = notval;
      }).to.throwException();
    });
Example #9
0
    it('switched to exporting if a value is written', function () {
      const def = new ObjDefine();
      def.writ('name');

      const obj = def.create();
      expect(flatten(obj)).to.not.have.property('name');

      obj.name = null;
      expect(flatten(obj)).to.not.have.property('name');

      obj.name = 'foo';
      expect(flatten(obj)).to.have.property('name', 'foo');
    });
Example #10
0
 it('does not export the computed value to JSON', function () {
   const def = new ObjDefine();
   def.comp('name', 'foo');
   expect(flatten(def.create())).to.not.have.property('name');
 });
Example #11
0
 it('exports the fact to JSON', function () {
   const def = new ObjDefine();
   def.fact('name', 'foo');
   expect(flatten(def.create())).to.have.property('name', 'foo');
 });