Fix an expired todo test (#6665)

* Fix a expired todo test

* only check TypeError

* Throw a specific TypeError

* fix async expect

* use return
master
fisker Cheung 2019-10-16 21:09:39 +08:00 committed by Lipis
parent 10bd71e478
commit 4750b1c25a
2 changed files with 20 additions and 7 deletions

View File

@ -19,6 +19,14 @@ const path = require("path");
* internally by the method wrapper. See withPlugins() in index.js.
*/
function getFileInfo(filePath, opts) {
if (typeof filePath !== "string") {
return Promise.reject(
new TypeError(
`expect \`filePath\` to be a string, got \`${typeof filePath}\``
)
);
}
return createIgnorer(opts.ignorePath, opts.withNodeModules).then(ignorer =>
_getFileInfo(
ignorer,
@ -34,6 +42,12 @@ function getFileInfo(filePath, opts) {
* @returns {FileInfoResult}
*/
getFileInfo.sync = function(filePath, opts) {
if (typeof filePath !== "string") {
throw new TypeError(
`expect \`filePath\` to be a string, got \`${typeof filePath}\``
);
}
const ignorer = createIgnorer.sync(opts.ignorePath, opts.withNodeModules);
return _getFileInfo(
ignorer,

View File

@ -106,16 +106,15 @@ describe("extracts file-info with inferredParser=foo when a plugin is hand-picke
});
test("API getFileInfo with no args", () => {
// TODO: change this to `rejects.toThrow()` when we upgrade to Jest >= 22
// https://github.com/facebook/jest/issues/3601
expect.assertions(1);
return prettier.getFileInfo().catch(err => {
expect(err).toBeDefined();
});
return expect(prettier.getFileInfo()).rejects.toThrow(
new TypeError("expect `filePath` to be a string, got `undefined`")
);
});
test("API getFileInfo.sync with no args", () => {
expect(() => prettier.getFileInfo.sync()).toThrow();
expect(() => prettier.getFileInfo.sync()).toThrow(
new TypeError("expect `filePath` to be a string, got `undefined`")
);
});
test("API getFileInfo with filepath only", () => {