Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed May 18, 2015
1 parent 477a711 commit 1aedf28
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/es6/lib/Utils/PromisesResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class PromisesResolver {
static allEvenFailed(promises) {
if (!Array.isArray(promises)) {
throw 'allEvenFailed can only handle an array of promises';
throw Error('allEvenFailed can only handle an array of promises');
}

return new Promise((resolve, reject) => {
Expand Down
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();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var assert = require('chai').assert;

import orderElement from "../../../lib/Utils/orderElement";

describe('Menu', () => {
describe('orderElement', () => {

describe("order()", () => {

Expand Down

0 comments on commit 1aedf28

Please sign in to comment.