Home Reference Source Test Repository

buildDocs/curryAll.spec.js

import * as tslib_1 from "tslib";
import { expect } from 'chai';
import { CurryAll } from './curryAll';
describe('curryAll', () => {
    it('should curry the method with default arity', () => {
        class MyClass {
            add(a, b) {
                return a + b;
            }
        }
        tslib_1.__decorate([
            CurryAll()
        ], MyClass.prototype, "add", null);
        const myClass = new MyClass();
        const add5 = myClass.add(5);
        expect(add5).to.be.an.instanceOf(Function);
        expect(add5(10)).to.equal(15);
    });
    it('should curry the method with fixed arity', () => {
        class MyClass {
            add(a, b, c) {
                return a + b * c;
            }
        }
        tslib_1.__decorate([
            CurryAll(2)
        ], MyClass.prototype, "add", null);
        const myClass = new MyClass();
        const add5 = myClass.add(5);
        expect(add5).to.be.an.instanceOf(Function);
        expect(add5(10, 2)).to.equal(25);
    });
    it('should not retain the class context', () => {
        class MyClass {
            add(a, b) {
                expect(this).to.equal(global);
            }
        }
        tslib_1.__decorate([
            CurryAll()
        ], MyClass.prototype, "add", null);
        const myClass = new MyClass();
        const add5 = myClass.add(5);
        add5(10);
    });
});