Don't show warning from spied console.warn (#12946)

This commit is contained in:
Nicolò Ribaudo 2021-03-02 15:22:20 +01:00 committed by GitHub
parent 8574aa33d5
commit 42752a430e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -274,10 +274,20 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
describe("util.js", () => { describe("util.js", () => {
describe("chmod", () => { describe("chmod", () => {
it("should warn the user if chmod fails", () => { it("should warn the user if chmod fails", () => {
const spyConsoleWarn = jest.spyOn(console, "warn"); const spyConsoleWarn = jest
// should expect a string as first argument .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"); chmod(100, "file.js");
expect(spyConsoleWarn).toHaveBeenCalledTimes(1); expect(spyConsoleWarn).toHaveBeenCalledTimes(1);
expect(spyConsoleWarn).toHaveBeenCalledWith(
"Cannot change permissions of file.js",
);
spyConsoleWarn.mockRestore(); spyConsoleWarn.mockRestore();
}); });
}); });