fix(tests): expectations of some async test where not working (#989)

This commit is contained in:
Christian C. Salvadó
2019-06-25 23:35:24 -06:00
committed by Angelos Chalaris
parent c89fd04ced
commit f4df77d62f
7 changed files with 20 additions and 19 deletions

View File

@ -5,7 +5,7 @@ test('chainAsync is a Function', () => {
});
let incrementer = 0;
test('Calls all functions in an array', () => {
test('Calls all functions in an array', done => {
chainAsync([
next => {
incrementer += 1;
@ -17,17 +17,19 @@ test('Calls all functions in an array', () => {
},
next => {
expect(incrementer).toEqual(2);
done();
}
]);
});
test('Last function does not receive "next" argument', () => {
test('Last function does not receive "next" argument', done => {
chainAsync([
next => {
next();
},
next => {
expect(next).toBe(undefined);
done();
}
]);
});

View File

@ -8,10 +8,5 @@ let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
test('Works with multiple promises', () => {
Pall(p1, p2, p3).then(
function(val) {
expect(val).toBe([1, 2, 3]);
},
function(reason) {}
);
return expect(Pall(p1, p2, p3)).resolves.toEqual([1, 2, 3]);
});

View File

@ -3,8 +3,10 @@ const {debounce} = require('./_30s.js');
test('debounce is a Function', () => {
expect(debounce).toBeInstanceOf(Function);
});
test('Works as expected', () => {
debounce(() => {
test('Works as expected', done => {
const debouncedFn = debounce(() => {
expect(true).toBeTruthy();
done();
});
debouncedFn();
});

View File

@ -3,10 +3,11 @@ const {delay} = require('./_30s.js');
test('delay is a Function', () => {
expect(delay).toBeInstanceOf(Function);
});
test('Works as expecting, passing arguments properly', () => {
test('Works as expecting, passing arguments properly', done => {
delay(
function(text) {
expect(text).toBe('test');
done();
},
1000,
'test'

View File

@ -3,8 +3,10 @@ const {hashNode} = require('./_30s.js');
test('hashNode is a Function', () => {
expect(hashNode).toBeInstanceOf(Function);
});
test('Produces the appropriate hash', () => {
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v =>
expect(v).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393')
test("Produces the appropriate hash", () => {
expect(
hashNode(JSON.stringify({ a: "a", b: [1, 2, 3, 4], foo: { c: "bar" } }))
).resolves.toBe(
"04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393"
);
});

View File

@ -5,5 +5,7 @@ test('runPromisesInSeries is a Function', () => {
});
const delay = d => new Promise(r => setTimeout(r, d));
test('Runs promises in series', () => {
runPromisesInSeries([() => delay(100), () => delay(200).then(() => expect(true).toBeTruthy())]);
return runPromisesInSeries([() => delay(100), () => delay(200)]).then(() =>
expect(true).toBeTruthy()
);
});

View File

@ -4,8 +4,5 @@ test('sleep is a Function', () => {
expect(sleep).toBeInstanceOf(Function);
});
test('Works as expected', () => {
async function sleepyWork() {
await sleep(1000);
expect(true).toBeTruthy();
}
return expect(sleep(1000)).resolves.toBe(undefined);
});