Skip to content

Commit 8d252fe

Browse files
committed
Fix testcode
1 parent 5103de8 commit 8d252fe

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/codegen/props/__tests__/position.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { afterAll, describe, expect, it, mock } from 'bun:test'
1+
import { afterAll, describe, expect, it, spyOn } from 'bun:test'
2+
import * as checkAssetNodeModule from '../../utils/check-asset-node'
3+
import * as isPageRootModule from '../../utils/is-page-root'
24
import { canBeAbsolute, getPositionProps } from '../position'
35

4-
mock.module('../../utils/check-asset-node', () => ({
5-
checkAssetNode: () => null,
6-
}))
6+
const checkAssetNodeSpy = spyOn(
7+
checkAssetNodeModule,
8+
'checkAssetNode',
9+
).mockReturnValue(null)
710

8-
mock.module('../../utils/is-page-root', () => ({
9-
isPageRoot: () => false,
10-
}))
11+
const isPageRootSpy = spyOn(isPageRootModule, 'isPageRoot').mockReturnValue(
12+
false,
13+
)
1114

1215
afterAll(() => {
13-
mock.restore()
16+
checkAssetNodeSpy.mockRestore()
17+
isPageRootSpy.mockRestore()
1418
})
1519

1620
describe('position', () => {

src/codegen/utils/__tests__/paint-to-css.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import { afterAll, beforeEach, describe, expect, mock, test } from 'bun:test'
1+
import {
2+
afterAll,
3+
beforeEach,
4+
describe,
5+
expect,
6+
mock,
7+
spyOn,
8+
test,
9+
} from 'bun:test'
10+
import * as checkAssetNodeModule from '../check-asset-node'
211
import { paintToCSS } from '../paint-to-css'
312
import { resetVariableCache } from '../variable-cache'
413

514
// mock asset checker to avoid real node handling
6-
mock.module('../check-asset-node', () => ({
7-
checkAssetNode: () => 'png',
8-
}))
15+
const checkAssetNodeSpy = spyOn(
16+
checkAssetNodeModule,
17+
'checkAssetNode',
18+
).mockReturnValue('png' as const)
919

1020
afterAll(() => {
11-
mock.restore()
21+
checkAssetNodeSpy.mockRestore()
1222
})
1323

1424
describe('paintToCSS', () => {

src/commands/__tests__/exportPagesAndComponents.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { afterAll, describe, expect, mock, test } from 'bun:test'
1+
import { afterAll, describe, expect, spyOn, test } from 'bun:test'
2+
import * as checkAssetNodeModule from '../../codegen/utils/check-asset-node'
23
import {
34
collectAssetNodes,
45
DEVUP_COMPONENTS,
@@ -7,21 +8,21 @@ import {
78
generateImportStatements,
89
} from '../exportPagesAndComponents'
910

10-
mock.module('../../codegen/utils/check-asset-node', () => ({
11-
checkAssetNode: (node: {
12-
type: string
13-
isAsset?: boolean
14-
}): string | null => {
11+
const checkAssetNodeSpy = spyOn(
12+
checkAssetNodeModule,
13+
'checkAssetNode',
14+
).mockImplementation(
15+
(node: { type: string; isAsset?: boolean }): 'svg' | 'png' | null => {
1516
if (node.type === 'VECTOR') return 'svg'
1617
if (node.type === 'STAR') return 'svg'
1718
if (node.type === 'POLYGON') return 'svg'
1819
if (node.isAsset && node.type === 'RECTANGLE') return 'png'
1920
return null
2021
},
21-
}))
22+
)
2223

2324
afterAll(() => {
24-
mock.restore()
25+
checkAssetNodeSpy.mockRestore()
2526
})
2627

2728
describe('DEVUP_COMPONENTS', () => {

0 commit comments

Comments
 (0)