buildDocs/debounce.spec.js
import * as tslib_1 from "tslib";
import { expect } from 'chai';
import { Debounce } from './debounce';
describe('debounce', () => {
it('should debounce the method', done => {
let calls = 0;
class MyClass {
fn() {
calls++;
}
}
tslib_1.__decorate([
Debounce(10)
], MyClass.prototype, "fn", null);
const myClass = new MyClass();
myClass.fn();
myClass.fn();
myClass.fn();
myClass.fn();
myClass.fn();
setTimeout(() => {
expect(calls).to.equal(1);
done();
}, 11);
});
it('should debounce the property setter', done => {
class MyClass {
constructor() {
this._value = 100;
}
set value(value) {
this._value = value;
}
get value() {
return this._value;
}
}
tslib_1.__decorate([
Debounce(10)
], 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();
}, 11);
});
it('should contain the flush and cancel methods', () => {
class MyClass {
fn() { }
}
tslib_1.__decorate([
Debounce(10)
], MyClass.prototype, "fn", null);
const myClass = new MyClass();
expect(myClass.fn.cancel).to.be.a('function');
expect(myClass.fn.flush).to.be.a('function');
});
});