From 42752a430e73d55d1da86201887cef3c98b5bafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 2 Mar 2021 15:22:20 +0100 Subject: [PATCH] Don't show warning from spied `console.warn` (#12946) --- packages/babel-cli/test/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index b605f3b623e7..a8fc722456cd 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -274,10 +274,20 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) { describe("util.js", () => { describe("chmod", () => { it("should warn the user if chmod fails", () => { - const spyConsoleWarn = jest.spyOn(console, "warn"); - // should expect a string as first argument + const spyConsoleWarn = jest + .spyOn(console, "warn") + .mockImplementation(() => {}); + + // The first argument should be a string. + // The real reason chmod will fail is due to wrong permissions, + // but this is enough to cause a failure. chmod(100, "file.js"); + expect(spyConsoleWarn).toHaveBeenCalledTimes(1); + expect(spyConsoleWarn).toHaveBeenCalledWith( + "Cannot change permissions of file.js", + ); + spyConsoleWarn.mockRestore(); }); });