diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/validations.js | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/validations.js')
-rw-r--r-- | test/validations.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/validations.js b/test/validations.js new file mode 100644 index 0000000..d1b3409 --- /dev/null +++ b/test/validations.js @@ -0,0 +1,63 @@ +'use strict' + +const t = require('tap') +const { test } = t +const { createServer } = require('http') +const { Client, errors } = require('..') + +const server = createServer((req, res) => { + res.setHeader('content-type', 'text/plain') + res.end('hello') + t.fail('server should never be called') +}) +t.teardown(server.close.bind(server)) + +server.listen(0, () => { + const url = `http://localhost:${server.address().port}` + + test('path', (t) => { + t.plan(4) + + const client = new Client(url) + t.teardown(client.close.bind(client)) + + client.request({ path: null, method: 'GET' }, (err, res) => { + t.type(err, errors.InvalidArgumentError) + t.equal(err.message, 'path must be a string') + }) + + client.request({ path: 'aaa', method: 'GET' }, (err, res) => { + t.type(err, errors.InvalidArgumentError) + t.equal(err.message, 'path must be an absolute URL or start with a slash') + }) + }) + + test('method', (t) => { + t.plan(2) + + const client = new Client(url) + t.teardown(client.close.bind(client)) + + client.request({ path: '/', method: null }, (err, res) => { + t.type(err, errors.InvalidArgumentError) + t.equal(err.message, 'method must be a string') + }) + }) + + test('body', (t) => { + t.plan(4) + + const client = new Client(url) + t.teardown(client.close.bind(client)) + + client.request({ path: '/', method: 'POST', body: 42 }, (err, res) => { + t.type(err, errors.InvalidArgumentError) + t.equal(err.message, 'body must be a string, a Buffer, a Readable stream, an iterable, or an async iterable') + }) + + client.request({ path: '/', method: 'POST', body: { hello: 'world' } }, (err, res) => { + t.type(err, errors.InvalidArgumentError) + t.equal(err.message, 'body must be a string, a Buffer, a Readable stream, an iterable, or an async iterable') + }) + }) +}) |