-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
47 lines (38 loc) · 1.36 KB
/
index.test.ts
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
// Stupid to use a library for this simple test, but to use hours to write test and debug the tests because
// it can't handle async code and promises is more important than productivity :)
import { promiseWrapper } from '.';
const fs = require('fs');
const readFile = promiseWrapper(fs.readFile);
readFile('JsonData/yourfile.json', 'utf8')
.then(console.log.bind(console))
.catch(console.error.bind(console));
test('promise-wrapper-resolved', done => {
function resultHandler({ error, result }) {
try {
expect(result).toBeTruthy();
expect(error).toBeNull();
} catch (e) {
done.fail(e);
}
done();
}
const readFile = promiseWrapper(fs.readFile);
readFile('.gitignore', 'utf8')
.then(result => resultHandler({ error: null, result }))
.catch(error => resultHandler({ error, result: null }));
});
test('promise-wrapper-catch', done => {
function resultHandler({ error, result }) {
try {
expect(error).toBeTruthy();
expect(result).toBeNull();
} catch (e) {
done.fail(e);
}
done();
}
const readFile = promiseWrapper(fs.readFile);
readFile('._blabla_gitignore', 'utf8')
.then(result => resultHandler({ error: null, result }))
.catch(error => resultHandler({ error, result: null }));
});