mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03: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:
32
packages/util/__tests__/lazy.test.ts
Normal file
32
packages/util/__tests__/lazy.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2020 The Sapphire Community and its contributors
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://github.com/sapphiredev/utilities/blob/main/LICENSE.md.
|
||||
*/
|
||||
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { lazy } from '../src/index.js';
|
||||
|
||||
describe('lazy', () => {
|
||||
test('GIVEN string callback THEN returns the same', () => {
|
||||
const callback = vi.fn(() => 'Lorem Ipsum');
|
||||
|
||||
const lazyStoredValue = lazy(callback);
|
||||
|
||||
expect(lazyStoredValue()).toEqual('Lorem Ipsum');
|
||||
});
|
||||
|
||||
test('GIVEN string callback with cached value THEN returns the same', () => {
|
||||
const callback = vi.fn(() => 'Lorem Ipsum');
|
||||
|
||||
const lazyStoredValue = lazy(callback);
|
||||
|
||||
lazyStoredValue();
|
||||
const cachedValue = lazyStoredValue();
|
||||
|
||||
expect(callback).toHaveBeenCalledOnce();
|
||||
expect(cachedValue).toEqual('Lorem Ipsum');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user