mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
feat(rest): use undici (#7747)
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: ckohen <chaikohen@gmail.com>
This commit is contained in:
@@ -1,11 +1,33 @@
|
||||
import nock from 'nock';
|
||||
import { DefaultRestOptions, REST } from '../src';
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import { Interceptable } from 'undici/types/mock-interceptor';
|
||||
import { genPath } from './util';
|
||||
import { REST } from '../src';
|
||||
|
||||
const api = new REST();
|
||||
|
||||
nock(`${DefaultRestOptions.api}/v${DefaultRestOptions.version}`).get('/simpleGet').reply(200, { test: true });
|
||||
let mockAgent: MockAgent;
|
||||
let mockPool: Interceptable;
|
||||
|
||||
beforeEach(() => {
|
||||
mockAgent = new MockAgent();
|
||||
mockAgent.disableNetConnect();
|
||||
setGlobalDispatcher(mockAgent);
|
||||
|
||||
mockPool = mockAgent.get('https://discord.com');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await mockAgent.close();
|
||||
});
|
||||
|
||||
test('no token', async () => {
|
||||
mockPool
|
||||
.intercept({
|
||||
path: genPath('/simpleGet'),
|
||||
method: 'GET',
|
||||
})
|
||||
.reply(200, 'Well this is awkward...');
|
||||
|
||||
const promise = api.get('/simpleGet');
|
||||
await expect(promise).rejects.toThrowError('Expected token to be set for this request, but none was present');
|
||||
await expect(promise).rejects.toBeInstanceOf(Error);
|
||||
|
||||
Reference in New Issue
Block a user