Home Reference Source Test Repository

buildDocs/delay.spec.js

import * as tslib_1 from "tslib";
import { expect } from 'chai';
import { spy } from 'sinon';
import { Delay } from './delay';
describe('delay', () => {
    it('should delay the method', done => {
        let _spy = spy();
        class MyClass {
            fn(...args) {
                expect(this, 'context').to.equal(myClass);
                _spy(...args);
            }
        }
        tslib_1.__decorate([
            Delay(15, '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();
        }, 16);
    });
    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([
            Delay(15)
        ], 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();
        }, 15);
    });
});