mirror of
https://github.com/axios/axios.git
synced 2026-04-14 03:11:58 +08:00
* chore: port karma tests * chore: port karma tests * chore: port karma tests * chore: tests * chore: tests * chore: tests * chore: fix issues with port collisions * refactor: utils tests * refactor: utils tests * refactor: utils tests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: tests to vitests * refactor: ci * chore: install pw deps * chore: fixx ai feedback * chore: wip compatability tests * chore: wip compatability tests * chore: wip compatability tests * refactor: wip smoke * chore: smoke test run * chore: update unzip * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: update testing * chore: skip tests that cannot run on node 16 and lower * chore: fix 16x under tests * chore: rest of tests * fix: functions and runs * feat: added tests for esm smoke * feat: added smoke * chore: ignore ai gen plans * chore: ci fixes * chore: fix small p2s
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import AxiosError from '../../../lib/core/AxiosError.js';
|
|
import validator from '../../../lib/helpers/validator.js';
|
|
|
|
describe('validator::assertOptions', () => {
|
|
it('should throw only if unknown an option was passed', () => {
|
|
let error;
|
|
try {
|
|
validator.assertOptions(
|
|
{
|
|
x: true,
|
|
},
|
|
{
|
|
y: validator.validators.boolean,
|
|
}
|
|
);
|
|
} catch (err) {
|
|
error = err;
|
|
}
|
|
expect(error).toBeInstanceOf(AxiosError);
|
|
expect(error.message).toBe('Unknown option x');
|
|
expect(error.code).toBe(AxiosError.ERR_BAD_OPTION);
|
|
|
|
expect(() => {
|
|
validator.assertOptions(
|
|
{
|
|
x: true,
|
|
},
|
|
{
|
|
x: validator.validators.boolean,
|
|
y: validator.validators.boolean,
|
|
}
|
|
);
|
|
}).not.toThrow(new Error('Unknown option x'));
|
|
});
|
|
|
|
it("should throw TypeError only if option type doesn't match", () => {
|
|
let error;
|
|
try {
|
|
validator.assertOptions(
|
|
{
|
|
x: 123,
|
|
},
|
|
{
|
|
x: validator.validators.boolean,
|
|
}
|
|
);
|
|
} catch (err) {
|
|
error = err;
|
|
}
|
|
expect(error).toBeInstanceOf(AxiosError);
|
|
expect(error.message).toBe('option x must be a boolean');
|
|
expect(error.code).toBe(AxiosError.ERR_BAD_OPTION_VALUE);
|
|
|
|
expect(() => {
|
|
validator.assertOptions(
|
|
{
|
|
x: true,
|
|
},
|
|
{
|
|
x: validator.validators.boolean,
|
|
y: validator.validators.boolean,
|
|
}
|
|
);
|
|
}).not.toThrow();
|
|
});
|
|
});
|