All files / test/asset AssetFileMap.test.ts

100% Statements 46/46
100% Branches 0/0
95.24% Functions 20/21
100% Lines 39/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 691x 1x 1x   1x   1x 1x 1x 1x 1x 1x   1x 1x 1x     1x 1x 1x         1x 1x   1x 1x     1x 1x   1x 1x 1x       1x 1x     1x 1x   1x 1x 1x       1x 1x     1x 1x   1x 1x 1x          
import { expect } from 'chai';
import { SinonSpy, spy } from 'sinon';
import { describe, it, before, after } from 'mocha';
 
import AssetFileMap from '../../src/asset/AssetFileMap';
 
describe('AssetFileMap',  () => {
  const mockArg = '/dev/null';
  describe('constructor', () => {
    it('should set passed value to own assetRoot property', () => {
      const instance = new AssetFileMap(mockArg);
      expect((instance as any).assetRoot).to.equal(mockArg);
    });
    it('should allocate empty Map to own entities property', () => {
      const instance = new AssetFileMap(mockArg);
      expect((instance as any).entities.constructor.name).to.equal('Map');
    });
 
    describe('when argument is not an absolute path', () => {
      it('should throw error', () => {
        expect(() => new AssetFileMap('dev/null')).to.throw(Error);
      });
    });
  });
 
  describe('instance methods', () => {
    let instance = new AssetFileMap(mockArg);
 
    describe('clear', () => {
      const subject = instance.clear.bind(instance);
      let clearSpy: SinonSpy;
 
      before(() => { clearSpy = spy((instance as any).entities, 'clear'); });
      after(() => clearSpy.restore());
 
      it('should wrap clear method of entity property', () => {
        subject();
        expect(clearSpy.calledOnce).to.equal(true);
      });
    });
 
    describe('get', () => {
      const subject = instance.get.bind(instance);
      let getSpy: SinonSpy;
 
      before(() => { getSpy = spy((instance as any).entities, 'get'); });
      after(() => getSpy.restore());
 
      it('should wrap get method of entity property', () => {
        subject();
        expect(getSpy.calledOnce).to.equal(true);
      });
    });
 
    describe('forEach', () => {
      const subject = instance.forEach.bind(instance);
      let forEachSpy: SinonSpy;
 
      before(() => { forEachSpy = spy((instance as any).entities, 'forEach'); });
      after(() => forEachSpy.restore());
 
      it('should wrap forEach method of entity property', () => {
        subject(() => {});
        expect(forEachSpy.calledOnce).to.equal(true);
      });
    });
  });
});