Compare commits

...

2 Commits

Author SHA1 Message Date
6cee2bbfd9 test: ignore coverage to test nextTickFn 2023-06-05 00:04:59 +01:00
009aabd2dd test: added test for enumObject. 2023-06-05 00:04:33 +01:00
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import { enumObject } from '../objects';
test('it should ignore and not crash with non-object', () => {
expect(Array.from(enumObject('string' as never))).toEqual([]);
});
test('it should ignore and not crash with null', () => {
expect(Array.from(enumObject(null))).toEqual([]);
});
test('it be able to iterate object', () => {
expect(Array.from(enumObject({ a: '1', b: '2' }))).toMatchInlineSnapshot(`
[
[
"a",
"1",
],
[
"b",
"2",
],
]
`);
});

View File

@ -1,10 +1,13 @@
type NextTickFn = (callback: () => void) => void;
/* c8 ignore start */
const nextTickFn =
typeof setImmediate !== 'undefined'
? (setImmediate as NextTickFn)
: typeof requestAnimationFrame !== 'undefined'
? (requestAnimationFrame as NextTickFn)
: (setTimeout as NextTickFn);
/* c8 ignore stop */
export async function nextTickAsync() {
return new Promise<void>((resolve) => nextTickFn(resolve));