mirror of
https://github.com/axios/axios.git
synced 2026-04-13 02:51:56 +08:00
* chore: port karma tests * chore: port karma tests * chore: port karma tests * chore: tests * chore: tests * chore: tests * chore: fix issues with port collisions * refactor: utils tests * refactor: utils tests * refactor: utils tests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: ci * chore: install pw deps * chore: fixx ai feedback * chore: wip compatability tests * chore: wip compatability tests * chore: wip compatability tests * refactor: wip smoke * chore: smoke test run * chore: update unzip * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: skip tests that cannot run on node 16 and lower * chore: fix 16x under tests * chore: rest of tests * fix: functions and runs * feat: added tests for esm smoke * feat: added smoke * chore: ignore ai gen plans * chore: ci fixes * chore: fix small p2s
70 lines
1.2 KiB
JavaScript
70 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import utils from '../../../lib/utils.js';
|
|
|
|
const { forEach } = utils;
|
|
|
|
describe('utils::forEach', () => {
|
|
it('should loop over an array', () => {
|
|
let sum = 0;
|
|
|
|
forEach([1, 2, 3, 4, 5], (val) => {
|
|
sum += val;
|
|
});
|
|
|
|
expect(sum).toEqual(15);
|
|
});
|
|
|
|
it('should loop over object keys', () => {
|
|
let keys = '';
|
|
let vals = 0;
|
|
const obj = {
|
|
b: 1,
|
|
a: 2,
|
|
r: 3,
|
|
};
|
|
|
|
forEach(obj, (v, k) => {
|
|
keys += k;
|
|
vals += v;
|
|
});
|
|
|
|
expect(keys).toEqual('bar');
|
|
expect(vals).toEqual(6);
|
|
});
|
|
|
|
it('should handle undefined gracefully', () => {
|
|
let count = 0;
|
|
|
|
forEach(undefined, () => {
|
|
count++;
|
|
});
|
|
|
|
expect(count).toEqual(0);
|
|
});
|
|
|
|
it('should make an array out of non-array argument', () => {
|
|
let count = 0;
|
|
|
|
forEach(
|
|
() => {},
|
|
() => {
|
|
count++;
|
|
}
|
|
);
|
|
|
|
expect(count).toEqual(1);
|
|
});
|
|
|
|
it('should handle non object prototype gracefully', () => {
|
|
let count = 0;
|
|
const data = Object.create(null);
|
|
data.foo = 'bar';
|
|
|
|
forEach(data, () => {
|
|
count++;
|
|
});
|
|
|
|
expect(count).toEqual(1);
|
|
});
|
|
});
|