timer.test.js 540 Bytes
/**
 * Timer 计时类测试
 *
 * @author: jiangfeng<jeff.jiang@yoho.cn>
 * @date: 2016/05/17
 */

const test = require('ava').test;
const Timer = require('../../library/timer');

const sleep = (timeout) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve();
        }, timeout);
    });
};

test.cb('timer class ', t => {
    let timer = new Timer();

    timer.put('test');
    sleep(300).then(() => {
        let diff = timer.put('test');

        t.true(diff >= 300);
        t.end();
    });
});