2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/test/specs/utils/forEach.spec.js
T
Jay ef3711d1b3 feat: implement prettier and fix all issues (#7385)
* feat: implement prettier and fix all issues

* fix: failing tests

* fix: implement feedback from codel, ai etc

* chore: dont throw in trim function

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix: incorrect fix

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-02-14 16:59:48 +02:00

69 lines
1.2 KiB
JavaScript

import utils from '../../../lib/utils';
const { forEach } = utils;
describe('utils::forEach', function () {
it('should loop over an array', function () {
let sum = 0;
forEach([1, 2, 3, 4, 5], function (val) {
sum += val;
});
expect(sum).toEqual(15);
});
it('should loop over object keys', function () {
let keys = '';
let vals = 0;
const obj = {
b: 1,
a: 2,
r: 3,
};
forEach(obj, function (v, k) {
keys += k;
vals += v;
});
expect(keys).toEqual('bar');
expect(vals).toEqual(6);
});
it('should handle undefined gracefully', function () {
let count = 0;
forEach(undefined, function () {
count++;
});
expect(count).toEqual(0);
});
it('should make an array out of non-array argument', function () {
let count = 0;
forEach(
function () {},
function () {
count++;
}
);
expect(count).toEqual(1);
});
it('should handle non object prototype gracefully', function () {
let count = 0;
const data = Object.create(null);
data.foo = 'bar';
forEach(data, function () {
count++;
});
expect(count).toEqual(1);
});
});