Files
30-seconds-of-code/test/promisify.test.js
2018-12-16 00:49:08 +09:00

19 lines
606 B
JavaScript

const expect = require('expect');
const {promisify} = require('./_30s.js');
test('promisify is a Function', () => {
expect(promisify).toBeInstanceOf(Function);
});
const x = promisify(Math.max);
test('Returns a promise', () => {
expect(x() instanceof Promise).toBeTruthy();
});
test('Runs the function provided', () => {
const delay = promisify((d, cb) => setTimeout(cb, d));
return delay(200).then(() => expect(true).toBeTruthy());
});
test('Returns a promise wrapped result', () => {
const return1 = promisify(cb => cb(null, 1));
return return1().then(result => expect(result).toBe(1));
});