-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathoptions.rejectUnauthorized.typecheck.test.ts
More file actions
48 lines (42 loc) · 1.35 KB
/
options.rejectUnauthorized.typecheck.test.ts
File metadata and controls
48 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { strict as assert } from 'node:assert';
import { describe, it, beforeAll, afterAll } from 'vite-plus/test';
import urllib from '../src/index.js';
import type { RequestOptions } from '../src/index.js';
import { startServer } from './fixtures/server.js';
describe('options.rejectUnauthorized.typecheck.test.ts', () => {
let close: any;
let _url: string;
beforeAll(async () => {
const { closeServer, url } = await startServer({ https: true });
close = closeServer;
_url = url;
});
afterAll(async () => {
await close();
});
it('should accept rejectUnauthorized on RequestOptions type', async () => {
// Type check: rejectUnauthorized should be assignable on RequestOptions
const options: RequestOptions = {
rejectUnauthorized: false,
dataType: 'json',
};
const response = await urllib.request(_url, options);
assert.equal(response.status, 200);
assert.equal(response.data.method, 'GET');
});
it('should accept rejectUnauthorized = true on RequestOptions type', async () => {
const options: RequestOptions = {
rejectUnauthorized: true,
dataType: 'json',
};
await assert.rejects(
async () => {
await urllib.request(_url, options);
},
(err: any) => {
assert.match(err.message, /signed certificate/);
return true;
},
);
});
});