Files
30-seconds-of-code/test/promisify.test.js
Christian C. Salvadó 83a6a6ea32 [ENHANCEMENT] Properly configure eslint to work with jest (#988)
* chore: make aware eslint that we use jest

By setting up the jest environment, we no longer need to declare the
'test' global in the configuration.

* chore: don't need to import expect, it's a jest environment global

* chore: don't need to import expect when creating undefined test
2019-06-18 08:34:45 +03:00

22 lines
696 B
JavaScript

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('Resolves a callback result', () => {
const resolve1 = promisify(cb => cb(null, 1));
return expect(resolve1()).resolves.toBe(1);
});
test('Rejects on error', () => {
const reject = promisify(cb => cb('error', null));
return expect(reject()).rejects.toMatch('error');
});