38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import { appendFunction } from './appendFunction';
|
|
describe('appendFunction', function () {
|
|
it('can append 2 functions', function () {
|
|
var counter = 0;
|
|
var function1 = function () { return counter++; };
|
|
var function2 = function () { return counter++; };
|
|
var function3 = appendFunction({}, function1, function2);
|
|
function3();
|
|
expect(counter).toEqual(2);
|
|
});
|
|
it('can deal with falsey values', function () {
|
|
var counter = 0;
|
|
var function1 = function () { return counter++; };
|
|
var function2 = function () { return counter++; };
|
|
var function3 = appendFunction({}, function1, undefined, null, function2);
|
|
function3();
|
|
expect(counter).toEqual(2);
|
|
});
|
|
it('preserves the parent', function () {
|
|
function add() {
|
|
this.counter++;
|
|
}
|
|
var Foo = /** @class */ (function () {
|
|
function Foo() {
|
|
this.counter = 0;
|
|
this.add = appendFunction(this, add, this.add);
|
|
}
|
|
Foo.prototype.add = function () {
|
|
this.counter++;
|
|
};
|
|
return Foo;
|
|
}());
|
|
var foo = new Foo();
|
|
foo.add();
|
|
expect(foo.counter).toEqual(2);
|
|
});
|
|
});
|
|
//# sourceMappingURL=appendFunction.test.js.map
|