-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
44 lines (44 loc) · 1.63 KB
/
index.test.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
// 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 :)
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
var fs = require('fs');
var readFile = _1.promiseWrapper(fs.readFile);
readFile('JsonData/yourfile.json', 'utf8')
.then(console.log.bind(console))
.catch(console.error.bind(console));
test('promise-wrapper-resolved', function (done) {
function resultHandler(_a) {
var error = _a.error, result = _a.result;
try {
expect(result).toBeTruthy();
expect(error).toBeNull();
}
catch (e) {
done.fail(e);
}
done();
}
var readFile = _1.promiseWrapper(fs.readFile);
readFile('.gitignore', 'utf8')
.then(function (result) { return resultHandler({ error: null, result: result }); })
.catch(function (error) { return resultHandler({ error: error, result: null }); });
});
test('promise-wrapper-catch', function (done) {
function resultHandler(_a) {
var error = _a.error, result = _a.result;
try {
expect(error).toBeTruthy();
expect(result).toBeNull();
}
catch (e) {
done.fail(e);
}
done();
}
var readFile = _1.promiseWrapper(fs.readFile);
readFile('._blabla_gitignore', 'utf8')
.then(function (result) { return resultHandler({ error: null, result: result }); })
.catch(function (error) { return resultHandler({ error: error, result: null }); });
});