Skip to content

Commit 8fc043d

Browse files
committed
Async Reduce Specs
- Fixed type in async sort readme - Removed pending tests from async reduce specs
1 parent cfd7525 commit 8fc043d

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed

src/async-sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { validateIsFunction, validateIsIterable } = require('./validation'),
55
/**
66
* Async Sort
77
* ==========
8-
* Asynchronously sorts and an iterable object and resolves when fully sorted
8+
* Asynchronously sorts and resolves when fully sorted
99
* note that the object is sorted in place and no copy is made
1010
* @async
1111
* @param {Function} [compare=compareByUnicode] - default is sort by item's unicode value
@@ -25,7 +25,7 @@ const asyncSort = (module.exports.asyncSort = async function asyncSort(
2525
/**
2626
* Async Sort Iterable
2727
* ===================
28-
* Asynchronously sorts and an iterable object and resolves when fully sorted
28+
* Asynchronously sorts an iterable object and resolves when fully sorted
2929
* note that the object is sorted in place and no copy is made
3030
* @async
3131
* @param {Object} iterable

test/async-reduce.spec.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { getArray } = require('./support/data-factory'),
1+
const { expect } = require('./support/chai'),
2+
{ getArray } = require('./support/data-factory'),
23
{ getCallback } = require('./support/helpers'),
34
{
45
rejectsWithError,
@@ -31,7 +32,6 @@ context('Async Reduce', () => {
3132
});
3233

3334
describe('Given a synchronous callback', () => {
34-
// eslint-disable-next-line no-unused-vars
3535
let result, callback, reducedAccumulator;
3636

3737
beforeEach(async () => {
@@ -42,20 +42,34 @@ context('Async Reduce', () => {
4242
reducedAccumulator = await asyncReduce(array, callback);
4343
});
4444

45-
it('Should run each callback in order', () =>
46-
ranCallbacksInOrder(result));
45+
it('Should run each callback in order', () => {
46+
ranCallbacksInOrder(result);
47+
48+
expect(result.length).to.be.greaterThan(
49+
0,
50+
'No callbacks were run.'
51+
);
52+
});
4753

4854
it('Should reduce each item in order', async () => {
49-
throw 'pending';
55+
array.every((element, index) => {
56+
return expect(reducedAccumulator[index]).to.equal(element);
57+
});
5058
});
5159

5260
it('Should resolve to the completed value accumulator', async () => {
53-
throw 'pending';
61+
result.every(({ item }, index) => {
62+
return expect(reducedAccumulator[index]).to.equal(item);
63+
});
64+
65+
expect(result.length).to.be.greaterThan(
66+
0,
67+
'No callbacks were run.'
68+
);
5469
});
5570
});
5671

5772
describe('Given an asynchronous callback', () => {
58-
// eslint-disable-next-line no-unused-vars
5973
let result, callback, reducedAccumulator;
6074

6175
beforeEach(async () => {
@@ -67,15 +81,30 @@ context('Async Reduce', () => {
6781
reducedAccumulator = await asyncReduce(array, callback);
6882
});
6983

70-
it('Should run each callback in order', () =>
71-
ranCallbacksInOrder(result));
84+
it('Should run each callback in order', () => {
85+
ranCallbacksInOrder(result);
86+
87+
expect(result.length).to.be.greaterThan(
88+
0,
89+
'No callbacks were run.'
90+
);
91+
});
7292

7393
it('Should reduce each item in order', async () => {
74-
throw 'pending';
94+
array.every((element, index) => {
95+
return expect(reducedAccumulator[index]).to.equal(element);
96+
});
7597
});
7698

7799
it('Should resolve to the completed value accumulator', async () => {
78-
throw 'pending';
100+
result.every(({ item }, index) => {
101+
return expect(reducedAccumulator[index]).to.equal(item);
102+
});
103+
104+
expect(result.length).to.be.greaterThan(
105+
0,
106+
'No callbacks were run.'
107+
);
79108
});
80109
});
81110

@@ -105,17 +134,22 @@ context('Async Reduce', () => {
105134
await asyncReduce(array, callback);
106135
});
107136

108-
it('Should have access to accumulator, currentValue, index and array on the callback', () =>
137+
it('Should have access to accumulator, currentValue, index and array on the callback', () => {
109138
hasAccessToCorrectArgumentsOnCallback(array, result, [
110139
'accumulator',
111140
'currentValue',
112141
'index',
113142
'array'
114-
]));
143+
]);
144+
145+
expect(result.length).to.be.greaterThan(
146+
0,
147+
'No callbacks were run.'
148+
);
149+
});
115150
});
116151

117152
describe('Given the optional accumulator parameter', () => {
118-
// eslint-disable-next-line no-unused-vars
119153
let result, callback, accumulator;
120154

121155
beforeEach(async () => {
@@ -125,7 +159,17 @@ context('Async Reduce', () => {
125159
});
126160

127161
it('Should have accesss to accumulator on all callback iterations', () => {
128-
throw 'pending';
162+
expect(
163+
result.every(
164+
({ accumulator: resultAccumulator }) =>
165+
resultAccumulator === accumulator
166+
)
167+
).to.be.true;
168+
169+
expect(result.length).to.be.greaterThan(
170+
0,
171+
'No callbacks were run.'
172+
);
129173
});
130174
});
131175
});

0 commit comments

Comments
 (0)