Skip to content

Commit 5f7fd00

Browse files
committed
Progress...
1 parent 2ac9c89 commit 5f7fd00

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

browser-extension/tests/lib/enhancers/github.test.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
1-
import { vi } from 'vitest'
1+
import { setupCommonMocks } from '../../mock-setup'
2+
3+
setupCommonMocks()
4+
25
import { EnhancerRegistry } from '../../../src/lib/registries'
36
import { describe, expect, usingHar } from '../../test-fixtures'
47

5-
vi.stubGlobal('defineContentScript', vi.fn())
6-
vi.mock('../../../src/overtype/overtype', () => {
7-
const mockConstructor = vi.fn().mockImplementation(() => [
8-
{
9-
container: document.createElement('div'),
10-
destroy: vi.fn(),
11-
focus: vi.fn(),
12-
getValue: vi.fn(() => ''),
13-
preview: document.createElement('div'),
14-
setValue: vi.fn(),
15-
textarea: document.createElement('textarea'),
16-
wrapper: document.createElement('div'),
17-
},
18-
])
19-
;(mockConstructor as any).setCodeHighlighter = vi.fn()
20-
return {
21-
default: mockConstructor,
22-
}
23-
})
24-
258
describe('github', () => {
269
usingHar('gh_pr').it('should identify gh_pr textarea and create proper spot object', async () => {
2710
const enhancers = new EnhancerRegistry()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { vi } from 'vitest'
2+
3+
/**
4+
* Sets up common mocks that are needed by most DOM-based tests.
5+
*
6+
* This function should be called at the top level of test files to ensure
7+
* proper hoisting of vi.mock calls.
8+
*
9+
* Example usage:
10+
* ```typescript
11+
* import { vi } from 'vitest'
12+
* import { setupCommonMocks } from '../mock-setup'
13+
*
14+
* setupCommonMocks()
15+
*
16+
* // ... rest of your test imports and code
17+
* ```
18+
*/
19+
export function setupCommonMocks() {
20+
// Mock the webextension defineContentScript global
21+
vi.stubGlobal('defineContentScript', vi.fn())
22+
23+
// Mock the OverType editor component
24+
vi.mock('../src/overtype/overtype', () => {
25+
const mockConstructor = vi.fn().mockImplementation(() => [
26+
{
27+
container: document.createElement('div'),
28+
destroy: vi.fn(),
29+
focus: vi.fn(),
30+
getValue: vi.fn(() => ''),
31+
preview: document.createElement('div'),
32+
setValue: vi.fn(),
33+
textarea: document.createElement('textarea'),
34+
wrapper: document.createElement('div'),
35+
},
36+
])
37+
;(mockConstructor as any).setCodeHighlighter = vi.fn()
38+
return {
39+
default: mockConstructor,
40+
}
41+
})
42+
}

0 commit comments

Comments
 (0)