-
-
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.
Merge pull request #16067 from rwjblue/update-backburner
[BUGFIX beta] Fix issues with `run.debounce` with only method and wait.
- Loading branch information
Showing
3 changed files
with
73 additions
and
15 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
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); | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -1141,9 +1141,9 @@ backbone@^1.1.2: | |
dependencies: | ||
underscore ">=1.8.3" | ||
|
||
backburner.js@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.0.0.tgz#ca78f7357776e24885f4dd4a887249b35fdd9c6c" | ||
backburner.js@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.0.2.tgz#d0049c0c6fd023084b66afeb82849f704ac6315e" | ||
|
||
[email protected]: | ||
version "1.0.2" | ||
|