mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: add @discordjs/util (#8591)
* feat: add @discordjs/util * fix: builders test * refactor: make rest use lazy for ESM import * chore: make requested changes * Apply suggestions from code review Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com> Co-authored-by: A. Román <kyradiscord@gmail.com> * chore: make requested changes and add tests * chore: regen lockfile * test: add type tests * chore: push missing files * chore: make requested changes * chore: update CI stuff * chore: fix lockfile * chore: make requested changes Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com> Co-authored-by: A. Román <kyradiscord@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
25
packages/util/__tests__/JSONEncodable.test.ts
Normal file
25
packages/util/__tests__/JSONEncodable.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { isJSONEncodable, type JSONEncodable } from '../src/index.js';
|
||||
|
||||
class Encodable implements JSONEncodable<{}> {
|
||||
public toJSON() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
describe('isJSONEncodable', () => {
|
||||
test('returns true if the object is JSON encodable', () => {
|
||||
expect(isJSONEncodable({ toJSON: () => ({}) })).toBeTruthy();
|
||||
expect(isJSONEncodable(new Encodable())).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns false if the object is not JSON encodable', () => {
|
||||
expect(isJSONEncodable({})).toBeFalsy();
|
||||
expect(isJSONEncodable(null)).toBeFalsy();
|
||||
expect(isJSONEncodable(undefined)).toBeFalsy();
|
||||
expect(isJSONEncodable(1)).toBeFalsy();
|
||||
expect(isJSONEncodable('')).toBeFalsy();
|
||||
expect(isJSONEncodable([])).toBeFalsy();
|
||||
expect(isJSONEncodable(() => {})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user