2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Warn about common option misspellings (#6489)

* chore(tests): add failing tests for baseUrl

* chore(tests): simplify to just warning

* feat: warn about likely-misspelled options

* chore: add semi-colon

* chore: add missing semi-colons

---------

Co-authored-by: Ell Bradshaw <ell@c9a.co>
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Ell Bradshaw
2024-09-26 12:31:24 -07:00
committed by GitHub
parent 00de614cd0
commit 8f3cde11d2
3 changed files with 29 additions and 0 deletions
+5
View File
@@ -97,6 +97,11 @@ class Axios {
}
}
validator.assertOptions(config, {
baseUrl: validators.spelling('baseURL'),
withXsrfToken: validators.spelling('withXSRFToken')
}, true);
// Set config.method
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
+8
View File
@@ -52,6 +52,14 @@ validators.transitional = function transitional(validator, version, message) {
};
};
validators.spelling = function spelling(correctSpelling) {
return (value, opt) => {
// eslint-disable-next-line no-console
console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
return true;
}
};
/**
* Assert object's properties type
*
+16
View File
@@ -71,6 +71,22 @@ describe('options', function () {
});
});
it('should warn about baseUrl', function (done) {
spyOn(window.console, 'warn');
const instance = axios.create({
baseUrl: 'http://example.com/'
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(window.console.warn).toHaveBeenCalledWith('baseUrl is likely a misspelling of baseURL');
expect(request.url).toBe('/foo');
done();
});
});
it('should ignore base URL if request URL is absolute', function (done) {
const instance = axios.create({
baseURL: 'http://someurl.com/'