Skip to content
File

Blob: src/workerd/api/node/tests/mimetype-test.js

javascript36 lines
1// Copyright (c) 2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4import { deepStrictEqual, ok, strictEqual } from 'node:assert';
5 
6import { MIMEType } from 'node:util';
7 
8export const test_ok = {
9 test() {
10 const mt = new MIMEType('TeXt/PlAiN; ChArsEt="utf-8"');
11 strictEqual(mt.type, 'text');
12 strictEqual(mt.subtype, 'plain');
13 strictEqual(mt.essence, 'text/plain');
14 strictEqual(mt.toString(), 'text/plain;charset=utf-8');
15 strictEqual(JSON.stringify(mt), '"text/plain;charset=utf-8"');
16 strictEqual(mt.params.get('charset'), 'utf-8');
17 ok(mt.params.has('charset'));
18 ok(!mt.params.has('boundary'));
19 mt.params.set('boundary', 'foo');
20 ok(mt.params.has('boundary'));
21 strictEqual(mt.toString(), 'text/plain;charset=utf-8; boundary=foo');
22 
23 deepStrictEqual(Array.from(mt.params), [
24 ['charset', 'utf-8'],
25 ['boundary', 'foo'],
26 ]);
27 
28 deepStrictEqual(Array.from(mt.params.keys()), ['charset', 'boundary']);
29 
30 deepStrictEqual(Array.from(mt.params.values()), ['utf-8', 'foo']);
31 
32 mt.params.delete('boundary');
33 ok(!mt.params.has('boundary'));
34 },
35};