-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
477a711
commit 1aedf28
Showing
3 changed files
with
50 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
src/javascripts/ng-admin/es6/tests/lib/Utils/PromisesResolverTest.js
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,48 @@ | ||
var assert = require('chai').assert; | ||
var expect = require('chai').expect; | ||
|
||
import PromisesResolver from "../../../lib/Utils/PromisesResolver"; | ||
|
||
describe('PromisesResolver', () => { | ||
|
||
describe("allEvenFailed()", () => { | ||
|
||
it('should throw an exception when the argument is not an array', () => { | ||
var error = 'allEvenFailed can only handle an array of promises'; | ||
|
||
expect(() => { PromisesResolver.allEvenFailed('nope') }).to.throw(error); | ||
expect(() => { PromisesResolver.allEvenFailed() }).to.throw(error); | ||
expect(() => { PromisesResolver.allEvenFailed(1) }).to.throw(error); | ||
}); | ||
|
||
it('should resolve all promises', (done) => { | ||
let p1Result = false, | ||
p2Result = false, | ||
p1 = new Promise((resolve, reject) => { | ||
resolve('p1'); | ||
}), | ||
p2 = new Promise((resolve, reject) => { | ||
resolve('p2'); | ||
}); | ||
|
||
p1.then((result) => { | ||
p1Result = result; | ||
}); | ||
p2.then((result) => { | ||
p2Result = result; | ||
}); | ||
|
||
let result = PromisesResolver.allEvenFailed([p1, p2]); | ||
|
||
// Check that all promises were resolved | ||
result.then(() => { | ||
assert.equal(p1Result, 'p1'); | ||
assert.equal(p1Result, 'p2'); | ||
|
||
// assert.equal does not throw an error when failing, | ||
// so we use a callback that timeout in case of error | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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