JEST: Quiet Jest tests output on expected failures (#2332)

This commit is contained in:
Michael Taylor
2025-10-05 16:31:15 -03:00
committed by GitHub
parent 8a2f8bb746
commit 370424af2d

View File

@@ -57,12 +57,17 @@ describe("setTheme", () => {
});
describe("Failure", () => {
let spyConErr: jest.Spied<typeof console.error>;
beforeEach(() => {
spyConErr = jest.spyOn(console, "error").mockImplementation(() => null);
});
test("Full theme", () => {
const ns = getNS();
const newTheme = ns.ui.getTheme();
newTheme.primary = "";
ns.ui.setTheme(newTheme);
const result = ns.ui.getTheme();
expect(spyConErr).toHaveBeenCalled();
expect(result.primary).toStrictEqual(defaultTheme.primary);
});
test("Partial theme", () => {
@@ -72,8 +77,12 @@ describe("setTheme", () => {
};
ns.ui.setTheme(newTheme as unknown as UserInterfaceTheme);
const result = ns.ui.getTheme();
expect(spyConErr).toHaveBeenCalled();
expect(result.primary).toStrictEqual(defaultTheme.primary);
});
afterEach(() => {
spyConErr.mockRestore();
});
});
});
@@ -123,12 +132,17 @@ describe("setStyles", () => {
});
describe("Failure", () => {
let spyConErr: jest.Spied<typeof console.error>;
beforeEach(() => {
spyConErr = jest.spyOn(console, "error").mockImplementation(() => null);
});
test("Full styles", () => {
const ns = getNS();
const newStyles = ns.ui.getStyles();
(newStyles.fontFamily as unknown) = 123;
ns.ui.setStyles(newStyles);
const result = ns.ui.getStyles();
expect(spyConErr).toHaveBeenCalled();
expect(result.fontFamily).toStrictEqual(defaultStyles.fontFamily);
});
test("Partial styles", () => {
@@ -138,7 +152,11 @@ describe("setStyles", () => {
};
ns.ui.setStyles(newStyles as unknown as IStyleSettings);
const result = ns.ui.getStyles();
expect(spyConErr).toHaveBeenCalled();
expect(result.fontFamily).toStrictEqual(defaultStyles.fontFamily);
});
afterEach(() => {
spyConErr.mockRestore();
});
});
});