Skip to content

Commit

Permalink
style(specs): reorder expected vs. actual comparisons for error-throw…
Browse files Browse the repository at this point in the history
…ing tests
  • Loading branch information
trxcllnt committed Sep 1, 2020
1 parent 111f854 commit 3cc1d8d
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 64 deletions.
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/catcherror-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('AsyncIterable#catchError error catches', async () => {
const res = await single(
throwError(err).pipe(
catchError(async (e: Error) => {
expect(err).toEqual(e);
expect(e).toEqual(err);
return of(42);
})
)
Expand Down
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/finalize-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('AsyncIterable#finally calls even with error', async () => {
try {
await hasNext(it, 0);
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}

expect(done).toBeTruthy();
Expand Down
10 changes: 5 additions & 5 deletions spec/asynciterable-operators/groupjoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('AsyncIterable#groupJoin left throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -78,7 +78,7 @@ test('AsyncIterable#groupJoin right throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -101,7 +101,7 @@ test('AsyncIterable#groupJoin left selector throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -124,7 +124,7 @@ test('AsyncIterable#groupJoin right selector throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -151,6 +151,6 @@ test('AsyncIterable#groupJoin result selector eventually throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
14 changes: 7 additions & 7 deletions spec/asynciterable-operators/orderby-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { orderBy, orderByDescending, thenBy, thenByDescending } from 'ix/asyncit

test('AsyncIterable#orderBy normal ordering', async () => {
const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0);
const ys = xs.pipe(orderBy(x => x));
const ys = xs.pipe(orderBy((x) => x));

const it = ys[Symbol.asyncIterator]();
for (let i = 0; i < 10; i++) {
Expand All @@ -18,7 +18,7 @@ test('AsyncIterable#orderBy normal ordering with thenBy throws', async () => {
const err = new Error();
const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0);
const ys = xs.pipe(
orderBy(x => x),
orderBy((x) => x),
thenBy(() => {
throw err;
})
Expand All @@ -28,7 +28,7 @@ test('AsyncIterable#orderBy normal ordering with thenBy throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -45,13 +45,13 @@ test('AsyncIterable#orderBy selector throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

test('AsyncIterable#orderByDescending normal ordering', async () => {
const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0);
const ys = xs.pipe(orderByDescending(x => x));
const ys = xs.pipe(orderByDescending((x) => x));

const it = ys[Symbol.asyncIterator]();
for (let i = 9; i >= 0; i--) {
Expand All @@ -65,7 +65,7 @@ test('AsyncIterable#orderByDescending normal ordering with thenByDescending thro
const err = new Error();
const xs = of(2, 6, 1, 5, 7, 8, 9, 3, 4, 0);
const ys = xs.pipe(
orderByDescending(x => x),
orderByDescending((x) => x),
thenByDescending(() => {
throw err;
})
Expand All @@ -75,6 +75,6 @@ test('AsyncIterable#orderByDescending normal ordering with thenByDescending thro
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/retry-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ test('AsyncIterable#retry finite eventually gives up', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/skip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ test('AsyncIterable#skip throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
6 changes: 3 additions & 3 deletions spec/asynciterable-operators/skipwhile-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { of } from 'ix/asynciterable';

test('AsyncIterable#skipWhile skips some', async () => {
const xs = of(1, 2, 3, 4);
const ys = xs.pipe(skipWhile(async x => x < 3));
const ys = xs.pipe(skipWhile(async (x) => x < 3));

const it = ys[Symbol.asyncIterator]();
await hasNext(it, 3);
Expand Down Expand Up @@ -34,7 +34,7 @@ test('AsyncIterable#skipWhile skips all', async () => {

test('AsyncIterable#skipWhile skips some another run', async () => {
const xs = of(1, 2, 3, 4, 3, 2, 1);
const ys = xs.pipe(skipWhile(x => x < 3));
const ys = xs.pipe(skipWhile((x) => x < 3));

const it = ys[Symbol.asyncIterator]();
await hasNext(it, 3);
Expand All @@ -58,7 +58,7 @@ test('AsyncIterable#skipWhile predicate throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand Down
2 changes: 1 addition & 1 deletion spec/asynciterable-operators/take-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ test('AsyncIterable#take throws with error', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
4 changes: 2 additions & 2 deletions spec/asynciterable-operators/takewhile-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { of } from 'ix/asynciterable';

test('AsyncIterable#takeWhile some match', async () => {
const xs = of(1, 2, 3, 4);
const ys = xs.pipe(takeWhile(x => x < 3));
const ys = xs.pipe(takeWhile((x) => x < 3));

const it = ys[Symbol.asyncIterator]();
await hasNext(it, 1);
Expand Down Expand Up @@ -55,6 +55,6 @@ test('AsyncIterable#takeWhile predicate throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
4 changes: 2 additions & 2 deletions spec/asynciterable-operators/tap-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('AsyncIterable#tap with error', async () => {
const source = throwError(err).pipe(
tap({
error: async (e) => {
expect(err).toEqual(e);
expect(e).toEqual(err);
ok = true;
},
})
Expand All @@ -57,7 +57,7 @@ test('AsyncIterable#tap with error', async () => {
for await (const _ of source) {
}
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}

expect(ok).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions spec/asynciterable/count-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('AsyncIterable#count throws', async () => {
try {
await count(xs);
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand Down Expand Up @@ -63,6 +63,6 @@ test('AsyncIterable#count predicate throws', async () => {
},
});
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
4 changes: 2 additions & 2 deletions spec/asynciterable/every-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('AsyncIterable#every throws', async () => {
try {
await every(xs, { predicate: async (x) => x % 2 === 0 });
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

Expand All @@ -39,6 +39,6 @@ test('AsyncIterable#every predicate throws', async () => {
},
});
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
16 changes: 8 additions & 8 deletions spec/asynciterable/from-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('AsyncIterable#from from promise list', async () => {
const xs: Iterable<Promise<number>> = [
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3)
Promise.resolve(3),
];
const res = from(xs);

Expand Down Expand Up @@ -127,7 +127,7 @@ test('AsyncIterable#from from promise with selector', async () => {
await noNext(it);
});

test('AsyncIterable#from from with non-iterable throws', done => {
test('AsyncIterable#from from with non-iterable throws', (done) => {
let error = false;
try {
from({} as any);
Expand Down Expand Up @@ -175,7 +175,7 @@ class TestObservable<T> implements Observable<T> {
}

test('AsyncIterable#fromObservable with completion', async () => {
const xs = new TestObservable<number>(obs => {
const xs = new TestObservable<number>((obs) => {
obs.next(42);
obs.complete();
return new EmptySubscription();
Expand All @@ -188,7 +188,7 @@ test('AsyncIterable#fromObservable with completion', async () => {
});

test('AsyncIterable#fromObservable with completion', async () => {
const xs = new TestObservable<number>(obs => {
const xs = new TestObservable<number>((obs) => {
obs.next(42);
obs.complete();
return new EmptySubscription();
Expand All @@ -201,7 +201,7 @@ test('AsyncIterable#fromObservable with completion', async () => {
});

test('AsyncIterable#fromObservable with multiple', async () => {
const xs = new TestObservable<number>(obs => {
const xs = new TestObservable<number>((obs) => {
let count = 0;
const interval = setInterval(() => {
obs.next(count++);
Expand All @@ -222,7 +222,7 @@ test('AsyncIterable#fromObservable with multiple', async () => {
});

test('AsyncIterable#fromObservable multiple with selector', async () => {
const xs = new TestObservable<number>(obs => {
const xs = new TestObservable<number>((obs) => {
let count = 0;
const interval = setInterval(() => {
obs.next(count++);
Expand All @@ -244,7 +244,7 @@ test('AsyncIterable#fromObservable multiple with selector', async () => {

test('AsyncIterable#fromObservable with error', async () => {
const err = new Error();
const xs = new TestObservable<number>(obs => {
const xs = new TestObservable<number>((obs) => {
obs.error(err);
return new EmptySubscription();
});
Expand All @@ -254,6 +254,6 @@ test('AsyncIterable#fromObservable with error', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
31 changes: 18 additions & 13 deletions spec/asynciterable/generate-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { hasNext, noNext } from '../asynciterablehelpers';
import { generate } from 'ix/asynciterable';

test('AsyncIterable#generate generates normal sequence', async () => {
const xs = generate(0, async x => x < 5, async x => x + 1, async x => x * x);
const xs = generate(
0,
async (x) => x < 5,
async (x) => x + 1,
async (x) => x * x
);

const it = xs[Symbol.asyncIterator]();
await hasNext(it, 0);
Expand All @@ -17,49 +22,49 @@ test('AsyncIterable#generate condition throws', async () => {
const err = new Error();
const xs = generate(
0,
async _ => {
async (_) => {
throw err;
},
async x => x + 1,
async x => x * x
async (x) => x + 1,
async (x) => x * x
);

const it = xs[Symbol.asyncIterator]();

try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

test('AsyncIterable#generate increment throws', async () => {
const err = new Error();
const xs = generate(
0,
async x => x < 5,
async _ => {
async (x) => x < 5,
async (_) => {
throw err;
},
async x => x * x
async (x) => x * x
);

const it = xs[Symbol.asyncIterator]();

try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});

test('AsyncIterable#generate result selector throws', async () => {
const err = new Error();
const xs = generate(
0,
async x => x < 5,
async x => x + 1,
async _ => {
async (x) => x < 5,
async (x) => x + 1,
async (_) => {
throw err;
}
);
Expand All @@ -69,6 +74,6 @@ test('AsyncIterable#generate result selector throws', async () => {
try {
await it.next();
} catch (e) {
expect(err).toEqual(e);
expect(e).toEqual(err);
}
});
Loading

0 comments on commit 3cc1d8d

Please sign in to comment.