Skip to content

Commit 2135fc1

Browse files
committed
refactor(apple,android): drop the unused assertThrowsAppError and split the details check
The affected audit surfaced both test helpers as dead exports and flagged the cyclomatic growth from the new reason/dispatched branches. Removing the sync assertion, which no test imported, and moving the machine-readable checks into their own function keeps each assertion at the complexity it had before. Refs #3181
1 parent cc90d27 commit 2135fc1

2 files changed

Lines changed: 24 additions & 22 deletions

File tree

‎packages/platform-android/src/__tests__/test-utils/app-error.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ type ExpectedAppError = {
1111
dispatched?: 'no' | 'unknown';
1212
};
1313

14-
function assertAppError(error: unknown, expected: ExpectedAppError): true {
15-
assert.ok(
16-
error instanceof AppError,
17-
`expected AppError, got ${error?.constructor?.name ?? typeof error}: ${String(error)}`,
18-
);
19-
assert.equal(error.code, expected.code);
20-
if (expected.message) assert.match(error.message, expected.message);
14+
/** Keys the assertion on the machine-readable refusal facts rather than on `message` prose. */
15+
function assertExpectedErrorDetails(error: AppError, expected: ExpectedAppError): void {
2116
if (expected.reason !== undefined) {
2217
assert.equal(
2318
error.details?.reason,
@@ -28,6 +23,16 @@ function assertAppError(error: unknown, expected: ExpectedAppError): true {
2823
if (expected.dispatched !== undefined) {
2924
assert.equal(error.details?.dispatched, expected.dispatched);
3025
}
26+
}
27+
28+
function assertAppError(error: unknown, expected: ExpectedAppError): true {
29+
assert.ok(
30+
error instanceof AppError,
31+
`expected AppError, got ${error?.constructor?.name ?? typeof error}: ${String(error)}`,
32+
);
33+
assert.equal(error.code, expected.code);
34+
if (expected.message) assert.match(error.message, expected.message);
35+
assertExpectedErrorDetails(error, expected);
3136
if (expected.hint !== undefined) {
3237
const { hint } = normalizeError(error);
3338
assert.ok(typeof hint === 'string', `expected a hint on ${error.code}, got ${String(hint)}`);
@@ -43,7 +48,3 @@ export async function assertRejectsAppError(
4348
): Promise<void> {
4449
await assert.rejects(run, (error: unknown) => assertAppError(error, expected));
4550
}
46-
47-
export function assertThrowsAppError(fn: () => unknown, expected: ExpectedAppError): void {
48-
assert.throws(fn, (error: unknown) => assertAppError(error, expected));
49-
}

‎packages/platform-apple/src/__tests__/app-error.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ type ExpectedAppError = {
1414
dispatched?: 'no' | 'unknown';
1515
};
1616

17-
function assertAppError(error: unknown, expected: ExpectedAppError): true {
18-
assert.ok(
19-
error instanceof AppError,
20-
`expected AppError, got ${error?.constructor?.name ?? typeof error}: ${String(error)}`,
21-
);
22-
assert.equal(error.code, expected.code);
23-
if (expected.message) assert.match(error.message, expected.message);
17+
/** Keys the assertion on the machine-readable refusal facts rather than on `message` prose. */
18+
function assertExpectedErrorDetails(error: AppError, expected: ExpectedAppError): void {
2419
if (expected.reason !== undefined) {
2520
assert.equal(
2621
error.details?.reason,
@@ -31,6 +26,16 @@ function assertAppError(error: unknown, expected: ExpectedAppError): true {
3126
if (expected.dispatched !== undefined) {
3227
assert.equal(error.details?.dispatched, expected.dispatched);
3328
}
29+
}
30+
31+
function assertAppError(error: unknown, expected: ExpectedAppError): true {
32+
assert.ok(
33+
error instanceof AppError,
34+
`expected AppError, got ${error?.constructor?.name ?? typeof error}: ${String(error)}`,
35+
);
36+
assert.equal(error.code, expected.code);
37+
if (expected.message) assert.match(error.message, expected.message);
38+
assertExpectedErrorDetails(error, expected);
3439
if (expected.normalizedMessage) {
3540
assert.match(normalizeError(error).message, expected.normalizedMessage);
3641
}
@@ -51,7 +56,3 @@ export async function assertRejectsAppError(
5156
): Promise<void> {
5257
await assert.rejects(run, (error: unknown) => assertAppError(error, expected));
5358
}
54-
55-
export function assertThrowsAppError(fn: () => unknown, expected: ExpectedAppError): void {
56-
assert.throws(fn, (error: unknown) => assertAppError(error, expected));
57-
}

0 commit comments

Comments
 (0)