Skip to content

Commit

Permalink
use assert.rejects
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Feb 28, 2024
1 parent a14e01b commit 454bb27
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ describe('storage', () => {
type requesterPaysFunction<
T = {} | typeof USER_PROJECT_OPTIONS,
R = {} | void,
> = (options: T) => Promise<R>;
> = (options?: T) => Promise<R>;

/**
* Accepts a function and runs 2 tests - a test where the requester pays
Expand All @@ -1805,21 +1805,16 @@ describe('storage', () => {
const failureMessage =
'Bucket is a requester pays bucket but no user project provided.';

let expectedError: unknown = null;

try {
// Should raise an error on requester pays bucket
await testFunction({});
} catch (e) {
expectedError = e;
}

console.log(JSON.stringify(expectedError));
assert(expectedError instanceof Error);
assert(
expectedError.message.includes(failureMessage),
`Expected '${expectedError.message}' to include '${failureMessage}'`
);
await assert.rejects(testFunction(), err => {
console.log(JSON.stringify(err));
console.log('');
assert(
(err as Error).message.includes(failureMessage),
`Expected '${
(err as Error).message
}' to include '${failureMessage}'`
);
});

// Validate the desired functionality
const results = await testFunction(USER_PROJECT_OPTIONS);
Expand Down

0 comments on commit 454bb27

Please sign in to comment.