Acme.BookStore.HttpApi.Host/node_modules/just-debounce/test.js
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
var debounce = require('./index.js')
var test = require('tape')
test('debauce', function (t) {
t.plan(3)
var fn = debounce(function (a, b) {
t.deepEqual(this, {call: 3}, 'context should be preserved')
t.equal(a, 30, 'should preserve args')
t.equal(b, 300, 'should preserve args')
}, 10)
fn.call({call: 1}, 10, 100)
fn.call({call: 2}, 20, 200)
setTimeout(function () {
fn.call({call: 3}, 30, 300)
}, 3)
})
test('multiple calls should extend delay', function (t) {
t.plan(4)
var wasDelayed = false
var fn = debounce(function (a, b) {
t.deepEqual(this, {call: 3}, 'context should be preserved')
t.equal(a, 30, 'should preserve args')
t.equal(b, 300, 'should preserve args')
t.ok(wasDelayed, 'should have waited longer than debounce period')
}, 6)
setTimeout(function longer () {
wasDelayed = true
}, 9)
fn.call({call: 1}, 10, 100)
setTimeout(function () {
fn.call({call: 2}, 20, 200)
setTimeout(function () {
fn.call({call: 3}, 30, 300)
}, 5)
}, 3)
})
test('multiple calls should not extend delay when guarantee is true', function (t) {
t.plan(8)
var first = true
var wasDelayed = false
var fn = debounce(function (a, b) {
if (first) {
t.deepEqual(this, {call: 2}, '1st context should be preserved')
t.equal(a, 20, '1st should preserve 1st args')
t.equal(b, 200, '1st should preserve 2nd args')
t.notOk(wasDelayed, 'should not have waited longer than debounce period')
first = false
后面还有 61 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
