Home Reference Source Test Repository

buildDocs/bindAll.spec.js

import * as tslib_1 from "tslib";
import { expect } from 'chai';
import { BindAll } from './bindAll';
describe('bindAll', () => {
    it('should bind all method to the context', () => {
        let context;
        class Parent {
            fn() {
                context = this;
            }
        }
        let MyClass = class MyClass extends Parent {
            fn2() {
                context = this;
            }
        };
        MyClass = tslib_1.__decorate([
            BindAll()
        ], MyClass);
        const myClass = new MyClass();
        myClass.fn.call(null);
        expect(context).to.equal(myClass);
        myClass.fn2.call(null);
        expect(context).to.equal(myClass);
    });
    it('should bind only specified methods to the context', () => {
        let context;
        class Parent {
            fn() {
                context = this;
            }
        }
        let MyClass = class MyClass extends Parent {
            fn2() {
                context = this;
            }
        };
        MyClass = tslib_1.__decorate([
            BindAll(['fn'])
        ], MyClass);
        const myClass = new MyClass();
        myClass.fn.call(null);
        expect(context).to.equal(myClass);
        myClass.fn2.call(null);
        expect(context).to.equal(null);
    });
});