Skip to content

Commit b3cf67b

Browse files
committed
fix: ensure that the test mocks don't leak on failures
1 parent aff757c commit b3cf67b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/getScrollBarSize.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ describe('getScrollBarSize', () => {
5757
const target = document.createElement('div');
5858
document.body.appendChild(target);
5959

60-
const nonce = 'test-nonce-123';
61-
getTargetScrollBarSize(target, { nonce });
60+
try {
61+
const nonce = 'test-nonce-123';
62+
getTargetScrollBarSize(target, { nonce });
6263

63-
expect(updateCSSSpy).toHaveBeenCalledWith(
64-
expect.any(String),
65-
expect.any(String),
66-
{ csp: { nonce } },
67-
);
68-
69-
updateCSSSpy.mockRestore();
70-
document.body.removeChild(target);
64+
expect(updateCSSSpy).toHaveBeenCalledWith(
65+
expect.any(String),
66+
expect.any(String),
67+
{ csp: { nonce } },
68+
);
69+
} finally {
70+
updateCSSSpy.mockRestore();
71+
document.body.removeChild(target);
72+
}
7173
});
7274
});
7375
});

0 commit comments

Comments
 (0)