buildDocs/defer.spec.js
import * as tslib_1 from "tslib";
import { expect } from 'chai';
import { spy } from 'sinon';
import { Defer } from './defer';
describe('defer', () => {
it('should defer the method', done => {
let _spy = spy();
class MyClass {
fn(...args) {
expect(this, 'context').to.equal(myClass);
_spy(...args);
}
}
tslib_1.__decorate([
Defer('test')
], MyClass.prototype, "fn", null);
const myClass = new MyClass();
myClass.fn(10);
expect(_spy.called).to.be.false;
setTimeout(() => {
expect(_spy.callCount).to.equal(1);
expect(_spy.getCalls()[0].args).to.eql([10, 'test']);
done();
}, 0);
});
it('should debounce the property setter', done => {
class MyClass {
constructor() {
this._value = 100;
}
set value(value) {
expect(this, 'context').to.equal(myClass);
this._value = value;
}
get value() {
return this._value;
}
}
tslib_1.__decorate([
Defer()
], MyClass.prototype, "value", null);
const myClass = new MyClass();
myClass.value = 5;
myClass.value = 15;
expect(myClass.value).to.equal(100);
setTimeout(() => {
expect(myClass.value).to.equal(15);
done();
}, 0);
});
});