Skip to content

Commit

Permalink
Stop spreading globalThis in tests (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding authored Sep 20, 2023
1 parent b8e821a commit ea41b43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('Crypto endowment', () => {
});

Object.assign(globalThis, {
...globalThis,
crypto: undefined,
SubtleCrypto: undefined,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ globalThis.removeEventListener = () => undefined;
describe('addEventListener', () => {
afterEach(() => {
Object.assign(globalThis, {
...globalThis,
addEventListener: originalAddEventListener,
process: originalProcess,
});
Expand All @@ -25,7 +24,7 @@ describe('addEventListener', () => {

it('uses on in Node.js', () => {
// Remove addEventListener
Object.assign(globalThis, { ...globalThis, addEventListener: undefined });
Object.assign(globalThis, { addEventListener: undefined });
const spy = jest.spyOn(globalThis.process, 'on');
const listener = () => undefined;
addEventListener('foo', listener);
Expand All @@ -35,8 +34,7 @@ describe('addEventListener', () => {
it('throws otherwise', () => {
// Remove addEventListener
Object.assign(globalThis, {
...globalThis,
process: { ...globalThis.process, on: undefined },
process: { on: undefined },
addEventListener: undefined,
});
const listener = () => undefined;
Expand All @@ -49,7 +47,6 @@ describe('addEventListener', () => {
describe('removeEventListener', () => {
afterEach(() => {
Object.assign(globalThis, {
...globalThis,
removeEventListener: originalRemoveEventListener,
process: originalProcess,
});
Expand All @@ -65,7 +62,6 @@ describe('removeEventListener', () => {
it('uses on in Node.js', () => {
// Remove removeEventListener
Object.assign(globalThis, {
...globalThis,
removeEventListener: undefined,
});
const spy = jest.spyOn(globalThis.process, 'removeListener');
Expand All @@ -77,8 +73,7 @@ describe('removeEventListener', () => {
it('throws otherwise', () => {
// Remove removeEventListener
Object.assign(globalThis, {
...globalThis,
process: { ...globalThis.process, removeListener: undefined },
process: { removeListener: undefined },
removeEventListener: undefined,
});
const listener = () => undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/snaps-utils/src/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('generateMockEndowments', () => {

it('returns global function for functions', () => {
const fetchMock = jest.fn().mockImplementationOnce(() => 'foo');
Object.assign(globalThis, { ...globalThis, fetch: fetchMock });
Object.assign(globalThis, { fetch: fetchMock });
const endowments = generateMockEndowments();
expect(endowments.fetch()).toBe('foo');
});

it('returns mock function for functions', () => {
// Remove fetch from isomorphic-fetch if present
Object.assign(globalThis, { ...globalThis, fetch: undefined });
Object.assign(globalThis, { fetch: undefined });
const endowments = generateMockEndowments();
expect(endowments.fetch()).toBe(true);
});
Expand Down

0 comments on commit ea41b43

Please sign in to comment.