Skip to content

Commit

Permalink
onExtensionStart - Testing: Properly reset the module state
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Mar 16, 2024
1 parent 160704f commit b896d5d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/on-extension-start.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import chrome from 'sinon-chrome';
import {describe, it, vi, expect} from 'vitest';
import {onExtensionStart} from './on-extension-start.js';
import {describe, it, vi, expect, beforeEach} from 'vitest';

const getMock = vi.fn().mockResolvedValue({});

Expand All @@ -15,8 +14,15 @@ chrome.storage.session = {
set: vi.fn(),
};

// `onExtensionStart` has global state
beforeEach(() => {
vi.resetModules();
});

describe('onExtensionStart', () => {
it('should register and run the listeners', async () => {
const {onExtensionStart} = await import('./on-extension-start.js');

getMock.mockResolvedValue({});

const listenerSpy = vi.fn();
Expand All @@ -33,6 +39,8 @@ describe('onExtensionStart', () => {
});

it('should not run the listeners after the registration time window has closed', async () => {
const {onExtensionStart} = await import('./on-extension-start.js');

const listenerSpy = vi.fn();
const listenerSpy2 = vi.fn();

Expand Down

0 comments on commit b896d5d

Please sign in to comment.