forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers-fetch-logic.spec.js
49 lines (42 loc) · 1.16 KB
/
users-fetch-logic.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import expect from 'expect';
import { usersFetchLogic } from '../src/users/logic';
import { of, throwError } from 'rxjs';
describe('usersFetchLogic', () => {
describe('using valid url', () => {
const results = [];
beforeEach((done) => {
const httpClient = url => {
return of({ // match shape of reqres.in api
data: [{ id: 1 }]
});
};
usersFetchLogic.process({ httpClient })
.subscribe({
next: x => results.push(x),
complete: done
});
});
it('should return promise that resolves to users', () => {
expect(results.length).toBe(1);
expect(results[0]).toEqual([{ id: 1 }]);
});
});
describe('invalid url', () => {
let rejectedValue;
beforeEach((done) => {
const httpClient = url => {
return throwError(new Error('not found 404'));
};
usersFetchLogic.process({ httpClient })
.subscribe({
error: err => {
rejectedValue = err;
done();
}
});
});
it('should reject to a 404 error', () => {
expect(rejectedValue.message).toBe('not found 404');
});
});
});