fix: 修复消息推送测试类型检查

This commit is contained in:
sunlei 2026-07-24 16:51:05 +08:00
parent 352e10ee39
commit e1d9ecfd66
2 changed files with 23 additions and 9 deletions

View File

@ -150,11 +150,11 @@ function getAllMessagePushRoutes(sourceFile: ts.SourceFile) {
/** Visits route objects so nested copies cannot evade the direct-child assertion. */ /** Visits route objects so nested copies cannot evade the direct-child assertion. */
function visit(node: ts.Node): void { function visit(node: ts.Node): void {
if ( if (ts.isObjectLiteralExpression(node)) {
ts.isObjectLiteralExpression(node) && const routeName = getStringProperty(node, 'name');
routeNames.has(getStringProperty(node, 'name')) if (typeof routeName === 'string' && routeNames.has(routeName)) {
) { matches.push(node);
matches.push(node); }
} }
ts.forEachChild(node, visit); ts.forEachChild(node, visit);

View File

@ -11,6 +11,15 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import MessageSubscriptionModal from './MessageSubscriptionModal'; import MessageSubscriptionModal from './MessageSubscriptionModal';
type MessageSubscriptionFormPatch = Partial<{
ddnsRecordId: string | undefined;
enabled: boolean;
name: string;
portForwardId: string | undefined;
remark: string | undefined;
sourceKey: string;
}>;
const mocks = vi.hoisted(() => { const mocks = vi.hoisted(() => {
const modalApi = { const modalApi = {
close: vi.fn(async () => {}), close: vi.fn(async () => {}),
@ -24,7 +33,7 @@ const mocks = vi.hoisted(() => {
getValues: vi.fn(), getValues: vi.fn(),
resetForm: vi.fn(async () => {}), resetForm: vi.fn(async () => {}),
resetValidate: vi.fn(async () => {}), resetValidate: vi.fn(async () => {}),
setValues: vi.fn(async () => {}), setValues: vi.fn(async (_patch: MessageSubscriptionFormPatch) => {}),
validate: vi.fn(async () => ({ valid: true })), validate: vi.fn(async () => ({ valid: true })),
}; };
return { return {
@ -424,9 +433,14 @@ describe('message subscription modal', () => {
expect(mocks.modalApi.close).toHaveBeenCalledOnce(); expect(mocks.modalApi.close).toHaveBeenCalledOnce();
expect(wrapper.emitted('saved')).toHaveLength(1); expect(wrapper.emitted('saved')).toHaveLength(1);
expect(mocks.modalApi.unlock).toHaveBeenCalledOnce(); expect(mocks.modalApi.unlock).toHaveBeenCalledOnce();
expect(mocks.modalApi.lock.mock.invocationCallOrder[0]).toBeLessThan( const lockOrder = mocks.modalApi.lock.mock.invocationCallOrder[0];
mocks.create.mock.invocationCallOrder[0], const createOrder = mocks.create.mock.invocationCallOrder[0];
); expect(lockOrder).toBeDefined();
expect(createOrder).toBeDefined();
if (lockOrder === undefined || createOrder === undefined) {
throw new Error('expected lock and create invocation order values');
}
expect(lockOrder).toBeLessThan(createOrder);
}); });
it('keeps the modal usable and emits nothing after a rejected mutation', async () => { it('keeps the modal usable and emits nothing after a rejected mutation', async () => {