Files
discord.js/packages/builders/__tests__/util.test.ts
Parbez 7ea3638dbc fix: don't mutate user provided array (#10014)
* fix(builders): don't mutate user provided array

* test: add normalize array tests

* chore: revert vscode autochange

* Update util.test.ts

* refactor: remove unnecessary clone

---------

Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Almeida <github@almeidx.dev>
2024-04-30 20:46:21 +00:00

31 lines
881 B
TypeScript

import { describe, test, expect } from 'vitest';
import { enableValidators, disableValidators, isValidationEnabled, normalizeArray } from '../src/index.js';
describe('validation', () => {
test('enables validation', () => {
enableValidators();
expect(isValidationEnabled()).toBeTruthy();
});
test('disables validation', () => {
disableValidators();
expect(isValidationEnabled()).toBeFalsy();
});
});
describe('normalizeArray', () => {
test('normalizes an array or array (when input is an array)', () => {
expect(normalizeArray([[1, 2, 3]])).toEqual([1, 2, 3]);
});
test('normalizes an array (when input is rest parameter)', () => {
expect(normalizeArray([1, 2, 3])).toEqual([1, 2, 3]);
});
test('always returns a clone', () => {
const arr = [1, 2, 3];
expect(normalizeArray([arr])).toEqual(arr);
expect(normalizeArray([arr])).not.toBe(arr);
});
});