-
-
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] Bring back Ember.Test.waiters.
Brings back `Ember.Test.waiters` and adds a feature flag for exposing `Ember.Test.checkWaiters`.
- Loading branch information
Showing
6 changed files
with
232 additions
and
4 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
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
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 |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import isEnabled from 'ember-metal/features'; | ||
import { | ||
registerWaiter, | ||
unregisterWaiter, | ||
checkWaiters, | ||
generateDeprecatedWaitersArray | ||
} from 'ember-testing/test/waiters'; | ||
|
||
class Waiters { | ||
constructor() { | ||
this._waiters = []; | ||
} | ||
|
||
add() { | ||
this._waiters.push([...arguments]); | ||
} | ||
|
||
register() { | ||
this.forEach((...args) => { | ||
registerWaiter(...args); | ||
}); | ||
} | ||
|
||
unregister() { | ||
this.forEach((...args) => { | ||
unregisterWaiter(...args); | ||
}); | ||
} | ||
|
||
forEach(callback) { | ||
for (let i = 0; i < this._waiters.length; i++) { | ||
let args = this._waiters[i]; | ||
|
||
callback(...args); | ||
} | ||
} | ||
|
||
check() { | ||
this.register(); | ||
let result = checkWaiters(); | ||
this.unregister(); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
QUnit.module('ember-testing: waiters', { | ||
setup() { | ||
this.waiters = new Waiters(); | ||
}, | ||
|
||
teardown() { | ||
this.waiters.unregister(); | ||
} | ||
}); | ||
|
||
QUnit.test('registering a waiter', function(assert) { | ||
assert.expect(2); | ||
|
||
let obj = { foo: true }; | ||
|
||
this.waiters.add(obj, function() { | ||
assert.ok(this.foo, 'has proper `this` context'); | ||
return true; | ||
}); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'is called'); | ||
return true; | ||
}); | ||
|
||
this.waiters.check(); | ||
}); | ||
|
||
QUnit.test('unregistering a waiter', function(assert) { | ||
assert.expect(2); | ||
|
||
let obj = { foo: true }; | ||
|
||
this.waiters.add(obj, function() { | ||
assert.ok(true, 'precond - waiter with context is registered'); | ||
return true; | ||
}); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter without context is registered'); | ||
return true; | ||
}); | ||
|
||
|
||
this.waiters.check(); | ||
this.waiters.unregister(); | ||
|
||
checkWaiters(); | ||
}); | ||
|
||
QUnit.test('checkWaiters returns false if all waiters return true', function(assert) { | ||
assert.expect(3); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter is registered'); | ||
|
||
return true; | ||
}); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter is registered'); | ||
|
||
return true; | ||
}); | ||
|
||
assert.notOk(this.waiters.check(), 'checkWaiters returns true if all waiters return true'); | ||
}); | ||
|
||
QUnit.test('checkWaiters returns true if any waiters return false', function(assert) { | ||
assert.expect(3); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter is registered'); | ||
|
||
return true; | ||
}); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter is registered'); | ||
|
||
return false; | ||
}); | ||
|
||
assert.ok(this.waiters.check(), 'checkWaiters returns false if any waiters return false'); | ||
}); | ||
|
||
QUnit.test('checkWaiters short circuits after first falsey waiter', function(assert) { | ||
assert.expect(2); | ||
|
||
this.waiters.add(function() { | ||
assert.ok(true, 'precond - waiter is registered'); | ||
|
||
return false; | ||
}); | ||
|
||
this.waiters.add(function() { | ||
assert.notOk(true, 'waiter should not be called'); | ||
}); | ||
|
||
assert.ok(this.waiters.check(), 'checkWaiters returns false if any waiters return false'); | ||
}); | ||
|
||
QUnit.test('generateDeprecatedWaitersArray provides deprecated access to waiters array', function(assert) { | ||
let waiter1 = () => {}; | ||
let waiter2 = () => {}; | ||
|
||
this.waiters.add(waiter1); | ||
this.waiters.add(waiter2); | ||
|
||
this.waiters.register(); | ||
|
||
let waiters; | ||
if (isEnabled('ember-testing-check-waiters')) { | ||
expectDeprecation(function() { | ||
waiters = generateDeprecatedWaitersArray(); | ||
}, /Usage of `Ember.Test.waiters` is deprecated/); | ||
} else { | ||
waiters = generateDeprecatedWaitersArray(); | ||
} | ||
|
||
assert.deepEqual(waiters, [ | ||
[null, waiter1], | ||
[null, waiter2] | ||
]); | ||
}); |