mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +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:
@@ -97,6 +97,11 @@ class Axios {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validator.assertOptions(config, {
|
||||||
|
baseUrl: validators.spelling('baseURL'),
|
||||||
|
withXsrfToken: validators.spelling('withXSRFToken')
|
||||||
|
}, true);
|
||||||
|
|
||||||
// Set config.method
|
// Set config.method
|
||||||
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* Assert object's properties type
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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) {
|
it('should ignore base URL if request URL is absolute', function (done) {
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: 'http://someurl.com/'
|
baseURL: 'http://someurl.com/'
|
||||||
|
|||||||
Reference in New Issue
Block a user