Skip to content

Commit 637fb1c

Browse files
committed
Add schema testcase
1 parent a2a7b25 commit 637fb1c

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/commands/devup/__tests__/apply-typography.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import { afterEach, describe, expect, mock, test } from 'bun:test'
1+
import {
2+
afterAll,
3+
afterEach,
4+
describe,
5+
expect,
6+
mock,
7+
spyOn,
8+
test,
9+
} from 'bun:test'
210
import { applyTypography } from '../apply-typography'
311

412
describe('applyTypography', () => {
513
afterEach(() => {
614
;(globalThis as { figma?: unknown }).figma = undefined
715
})
816

17+
afterAll(() => {
18+
mock.restore()
19+
})
20+
921
test('applies typography to a newly created style', async () => {
1022
const styleObj = { name: '' } as unknown as TextStyle
1123
const createTextStyle = mock(() => styleObj)
@@ -58,14 +70,15 @@ describe('applyTypography', () => {
5870
test('notifies on font load failure and leaves style untouched', async () => {
5971
const styleObj = { name: '' } as unknown as TextStyle
6072
const createTextStyle = mock(() => styleObj)
61-
const loadFontAsync = mock(() => Promise.reject(new Error('font')))
73+
const loadFontAsync = mock(() => Promise.reject('font'))
6274
const notify = mock(() => {})
6375

6476
;(globalThis as { figma?: unknown }).figma = {
6577
createTextStyle,
6678
loadFontAsync,
6779
notify,
6880
} as unknown as typeof figma
81+
spyOn(console, 'error').mockImplementation(() => {})
6982

7083
await applyTypography(
7184
'mobile/title',
@@ -83,6 +96,10 @@ describe('applyTypography', () => {
8396
expect.stringContaining('Failed to create text style'),
8497
{ error: true },
8598
)
99+
expect(console.error).toHaveBeenCalledWith(
100+
'Failed to create text style',
101+
'font',
102+
)
86103
})
87104

88105
test('applies px letterSpacing and percent lineHeight on existing style', async () => {

src/commands/devup/__tests__/index.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
afterAll,
23
afterEach,
34
beforeEach,
45
describe,
@@ -22,6 +23,10 @@ import * as downloadXlsxModule from '../utils/download-devup-xlsx'
2223
import * as getColorCollectionModule from '../utils/get-devup-color-collection'
2324
import * as uploadXlsxModule from '../utils/upload-devup-xlsx'
2425

26+
afterAll(() => {
27+
mock.restore()
28+
})
29+
2530
describe('devup commands', () => {
2631
const downloadFileMock = mock(() => Promise.resolve(undefined))
2732
const downloadXlsxMock = mock(() => Promise.resolve(undefined))
@@ -382,7 +387,7 @@ describe('devup commands', () => {
382387
textSegmentToTypographySpy = spyOn(
383388
textSegmentToTypographyModule,
384389
'textSegmentToTypography',
385-
).mockReturnValue(null)
390+
).mockReturnValue(null as unknown as DevupTypography)
386391

387392
;(globalThis as { figma?: unknown }).figma = {
388393
util: { rgba: (v: unknown) => v },
@@ -609,7 +614,8 @@ describe('devup commands', () => {
609614
name: '',
610615
}) as unknown as TextStyle,
611616
)
612-
const loadFontAsync = mock(() => Promise.reject(new Error('font')))
617+
const loadFontAsync = mock(() => Promise.reject('font'))
618+
spyOn(console, 'error').mockImplementation(() => {})
613619

614620
;(globalThis as { figma?: unknown }).figma = {
615621
util: { rgba: (v: unknown) => v },
@@ -639,6 +645,10 @@ describe('devup commands', () => {
639645
expect.stringContaining('Failed to create text style'),
640646
expect.any(Object),
641647
)
648+
expect(console.error).toHaveBeenCalledWith(
649+
'Failed to create text style',
650+
'font',
651+
)
642652
})
643653

644654
test('importDevup sets typography spacing values', async () => {

0 commit comments

Comments
 (0)