Skip to content

Commit 3d20b2e

Browse files
fix(fetch): cleanup tests
1 parent e248db8 commit 3d20b2e

File tree

8 files changed

+42
-41
lines changed

8 files changed

+42
-41
lines changed

packages/operators/src/fetch/autoPagination.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { concatAll, map, of } from 'rxjs';
22
import { beforeEach, describe, expect, test } from 'vitest';
33

4+
import { log } from '../log';
45
import { autoPagination } from './autoPagination';
56
import { resolveJSON } from './resolve';
67

@@ -26,16 +27,15 @@ describe('auto pagination', function () {
2627
}
2728
}
2829
}),
30+
log(false),
2931
resolveJSON(),
32+
log(false),
3033
map(({ products }) => products),
3134
concatAll()
3235
)
3336
.subscribe({
3437
next: e => console.log(e),
35-
complete: () => {
36-
console.log('COMPLETE');
37-
done();
38-
}
38+
complete: () => done()
3939
});
4040
});
4141
});

packages/operators/src/fetch/concurrentDownload.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ describe('multi fetch', function () {
3030
)
3131
.subscribe({
3232
next: e => console.log(e),
33-
complete: () => {
34-
console.log('COMPLETE');
35-
done();
36-
}
33+
complete: () => done()
3734
});
3835
});
3936
});

packages/operators/src/fetch/download.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock';
22
import { of } from 'rxjs';
33
import { afterEach, test, describe, beforeEach, expect } from 'vitest';
44

5+
import { log } from '../log.js';
56
import { download, downloadJSON } from './download.js';
67

78
describe('download operator', function () {
@@ -27,13 +28,12 @@ describe('download operator', function () {
2728
test('successfull download', () =>
2829
new Promise(done => {
2930
of('https://httpbin.org/my-url-fast')
30-
.pipe(downloadJSON())
31+
.pipe(downloadJSON(), log(false))
3132
.subscribe({
3233
next: data => {
3334
expect(data).deep.equal({ hello: 'fast world' });
34-
done();
3535
},
36-
complete: e => console.log('COMPLETE', e)
36+
complete: e => done()
3737
});
3838
}));
3939
});

packages/operators/src/fetch/lazyPagination.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { concatMap, map } from 'rxjs';
22

33
import { concurrentDownload } from './concurrentDownload';
44

5-
export const lazyPagination = ({ createRoute }) => {
5+
export const lazyPagination = ({ resolveRoute }) => {
66
return source =>
77
source.pipe(
88
concatMap(({ url, pager, concurrent }) => {
99
return pager.pipe(
10-
map(options => createRoute(url, options)),
10+
map(options => resolveRoute(url, options)),
1111
concurrentDownload(concurrent)
1212
);
1313
})

packages/operators/src/fetch/lazyPagination.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { concatAll, map, of, Subject } from 'rxjs';
22
import { beforeEach, describe, expect, test } from 'vitest';
33

4+
import { log } from '../log';
45
import { lazyPagination } from './lazyPagination';
56
import { resolveJSON } from './resolve';
67

@@ -16,24 +17,24 @@ describe('lazy pagination operator', function () {
1617
of({ url: new URL('https://dummyjson.com/products'), pager, concurrent: 4 })
1718
.pipe(
1819
lazyPagination({
19-
createRoute: (url, { value, limit = 10 }) => {
20+
resolveRoute: (url, { value, limit = 10 }) => {
2021
const newUrl = new URL(`${url}`);
2122
newUrl.searchParams.set('skip', value * limit);
2223
newUrl.searchParams.set('limit', limit);
2324
newUrl.searchParams.set('select', 'title,price');
2425
return newUrl;
2526
}
2627
}),
28+
log(false),
2729
resolveJSON(),
30+
log(false),
2831
map(({ products }) => products),
29-
concatAll()
32+
concatAll(),
33+
log(false)
3034
)
3135
.subscribe({
3236
next: e => console.log(e),
33-
complete: () => {
34-
console.log('COMPLETE');
35-
done();
36-
}
37+
complete: () => done()
3738
});
3839

3940
pager.next({ value: 2 });

packages/operators/src/fetch/polling.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ describe('polling', function () {
99
});
1010

1111
test('auto polling', async function () {
12-
of({ url: new URL('https://dummyjson.com/products') })
13-
.pipe(
14-
polling({
15-
validateResult: data => {
16-
return data.total > data.skip + data.limit;
17-
}
18-
})
19-
// map(({ data: { products } }) => products),
20-
// concatAll()
21-
)
22-
.subscribe({
23-
next: e => console.log('aha'),
24-
complete: () => console.log('COMPLETE')
25-
});
26-
27-
await new Promise(resolve => setTimeout(resolve, 5000));
12+
return new Promise(done => {
13+
of({ url: new URL('https://dummyjson.com/products') })
14+
.pipe(
15+
polling({
16+
validateResult: data => {
17+
return data.total > data.skip + data.limit;
18+
}
19+
})
20+
// map(({ data: { products } }) => products),
21+
// concatAll()
22+
)
23+
.subscribe({
24+
next: e => console.log('aha'),
25+
complete: () => done()
26+
});
27+
});
2828
});
2929
});

packages/operators/src/fetch/request.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock';
22
import { of } from 'rxjs';
33
import { afterEach, test, describe, beforeEach, expect } from 'vitest';
44

5+
import { log } from '../log.js';
56
import { request } from './request.js';
67

78
describe('request observable with default operators', function () {
@@ -26,7 +27,7 @@ describe('request observable with default operators', function () {
2627
test('successfull request', () =>
2728
new Promise(done => {
2829
of('https://httpbin.org/my-url-fast')
29-
.pipe(request())
30+
.pipe(request(), log(false))
3031
.subscribe({
3132
next: resp => {
3233
expect(resp).deep.includes({ ok: true });

packages/operators/src/fetch/upload.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ describe('request observable with default operators', function () {
3838
return new Promise(done => {
3939
of(req)
4040
.pipe(upload(), log(false), resolveJSON(), log(false))
41-
.subscribe(e => {
42-
expect(e)
43-
.deep.includes({ originalname: 'test_image.jpg' })
44-
.have.all.keys('filename', 'location');
45-
done();
41+
.subscribe({
42+
next: e => {
43+
expect(e)
44+
.deep.includes({ originalname: 'test_image.jpg' })
45+
.have.all.keys('filename', 'location');
46+
},
47+
complete: () => done()
4648
});
4749
});
4850
});

0 commit comments

Comments
 (0)