Skip to content

Commit

Permalink
[BUGFIX beta] Add simple Ember.run.debounce tests.
Browse files Browse the repository at this point in the history
Some very basic tests around common usage patterns to help prevent
regressions in the future.
  • Loading branch information
rwjblue committed Jan 5, 2018
1 parent d3d667d commit db305cf
Showing 1 changed file with 69 additions and 11 deletions.
80 changes: 69 additions & 11 deletions packages/ember-metal/tests/run_loop/debounce_test.js
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);
}
});

0 comments on commit db305cf

Please sign in to comment.