-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX beta] Add simple Ember.run.debounce tests.
Some very basic tests around common usage patterns to help prevent regressions in the future.
- Loading branch information
Showing
1 changed file
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,80 @@ | ||
import { run } from '../..'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
const originalDebounce = run.backburner.debounce; | ||
let wasCalled = false; | ||
|
||
moduleFor('Ember.run.debounce', class extends AbstractTestCase { | ||
constructor() { | ||
super(); | ||
['@test Ember.run.debounce - with target, with method, without args'](assert) { | ||
let done = assert.async(); | ||
|
||
let calledWith = []; | ||
let target = { | ||
someFunc(...args) { | ||
calledWith.push(args); | ||
} | ||
}; | ||
|
||
run.debounce(target, target.someFunc, 10); | ||
run.debounce(target, target.someFunc, 10); | ||
run.debounce(target, target.someFunc, 10); | ||
|
||
setTimeout(() => { | ||
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments'); | ||
done(); | ||
}, 20); | ||
} | ||
|
||
['@test Ember.run.debounce - with target, with method name, without args'](assert) { | ||
let done = assert.async(); | ||
|
||
let calledWith = []; | ||
let target = { | ||
someFunc(...args) { | ||
calledWith.push(args); | ||
} | ||
}; | ||
|
||
run.backburner.debounce = function() { wasCalled = true; }; | ||
run.debounce(target, 'someFunc', 10); | ||
run.debounce(target, 'someFunc', 10); | ||
run.debounce(target, 'someFunc', 10); | ||
|
||
setTimeout(() => { | ||
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments'); | ||
done(); | ||
}, 20); | ||
} | ||
|
||
teardown() { | ||
run.backburner.debounce = originalDebounce; | ||
['@test Ember.run.debounce - without target, without args'](assert) { | ||
let done = assert.async(); | ||
|
||
let calledWith = []; | ||
function someFunc(...args) { | ||
calledWith.push(args); | ||
} | ||
|
||
run.debounce(someFunc, 10); | ||
run.debounce(someFunc, 10); | ||
run.debounce(someFunc, 10); | ||
|
||
setTimeout(() => { | ||
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments'); | ||
done(); | ||
}, 20); | ||
} | ||
|
||
['@test Ember.run.debounce uses Backburner.debounce'](assert) { | ||
run.debounce(() => {}); | ||
assert.ok(wasCalled, 'Ember.run.debounce used'); | ||
['@test Ember.run.debounce - without target, with args'](assert) { | ||
let done = assert.async(); | ||
|
||
let calledWith = []; | ||
function someFunc(...args) { | ||
calledWith.push(args); | ||
} | ||
|
||
run.debounce(someFunc, { isFoo: true }, 10); | ||
run.debounce(someFunc, { isBar: true }, 10); | ||
run.debounce(someFunc, { isBaz: true }, 10); | ||
|
||
setTimeout(() => { | ||
assert.deepEqual(calledWith, [ [ { isBaz: true } ] ], 'someFunc called once with correct arguments'); | ||
done(); | ||
}, 20); | ||
} | ||
}); |