From 4750b1c25aa75ebbc7464610e8dde02bbaab98a4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 16 Oct 2019 21:09:39 +0800 Subject: [PATCH] Fix an expired todo test (#6665) * Fix a expired todo test * only check TypeError * Throw a specific TypeError * fix async expect * use return --- src/common/get-file-info.js | 14 ++++++++++++++ tests_integration/__tests__/file-info.js | 13 ++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/common/get-file-info.js b/src/common/get-file-info.js index a587b31e..fb5474dc 100644 --- a/src/common/get-file-info.js +++ b/src/common/get-file-info.js @@ -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, diff --git a/tests_integration/__tests__/file-info.js b/tests_integration/__tests__/file-info.js index ac7c32ca..444045fd 100644 --- a/tests_integration/__tests__/file-info.js +++ b/tests_integration/__tests__/file-info.js @@ -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", () => {