Files
discordeno/packages/utils/tests/casting.spec.ts
Fleny 27c261fee2 formatter: Use semicolons (#4686)
I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
2026-01-17 21:54:15 +01:00

90 lines
2.2 KiB
TypeScript

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { camelize, snakelize, snakeToCamelCase } from '../src/casing.js';
describe('casting.ts', () => {
describe('camelize function', () => {
it('will convert snake case object to camel case object', () => {
expect(
camelize({
test_ax_by_cz: 'dummy_dx_ey_fz',
testgxhyiz: 'dummyjxkylz',
32: 'adw_dw',
}),
).to.deep.equal({
testAxByCz: 'dummy_dx_ey_fz',
testgxhyiz: 'dummyjxkylz',
32: 'adw_dw',
});
});
it('will convert array of snake case object to camel case object', () => {
expect(
camelize([
{
test_ax_by_cz: 'dummy_dx_ey_fz',
},
{
test_gx_hy_iz: 'dummy_jx_ky_lz',
},
]),
).to.deep.equal([
{
testAxByCz: 'dummy_dx_ey_fz',
},
{
testGxHyIz: 'dummy_jx_ky_lz',
},
]);
});
describe('snakeToCamelCase function', () => {
it('will convert string snake case to camel case', () => {
expect(snakeToCamelCase('sd_sd')).to.equal('sdSd');
});
});
});
describe('snakelize function', () => {
it('will convert snake case object to camel case object', () => {
expect(
snakelize({
testAxByCz: 'dummy_dx_ey_fz',
testgxhyiz: 'dummyjxkylz',
32: 'adw_dw',
}),
).to.deep.equal({
test_ax_by_cz: 'dummy_dx_ey_fz',
testgxhyiz: 'dummyjxkylz',
32: 'adw_dw',
});
});
it('will convert array of snake case object to camel case object', () => {
expect(
snakelize([
{
testAxByCz: 'dummy_dx_ey_fz',
},
{
testGxHyIz: 'dummy_jx_ky_lz',
},
]),
).to.deep.equal([
{
test_ax_by_cz: 'dummy_dx_ey_fz',
},
{
test_gx_hy_iz: 'dummy_jx_ky_lz',
},
]);
});
describe('snakeToCamelCase function', () => {
it('will convert string snake case to camel case', () => {
expect(snakeToCamelCase('sd_sd')).to.equal('sdSd');
});
});
});
});