1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Sync rollbackToPreviousProvider tests w/ core (#19428)

This makes it easier to visually compare differences in the
NetworkController unit tests between core and this repo.
This commit is contained in:
Elliot Winkler 2023-06-14 09:23:16 -06:00 committed by GitHub
parent b43900f743
commit 9c91db5d31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 369 additions and 553 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,45 @@ beforeEach(() => {
});
expect.extend({
/**
* Tests that the given promise is fulfilled within a certain amount of time
* (which is the default time that Jest tests wait before timing out as
* configured in the Jest configuration file).
*
* Inspired by <https://stackoverflow.com/a/68409467/260771>.
*
* @param {Promise<any>} promise - The promise to test.
* @returns The result of the matcher.
*/
async toBeFulfilled(promise) {
if (this.isNot) {
throw new Error(
"Using `.not.toBeFulfilled(...)` is not supported. Use `.rejects` to test the promise's rejection value instead.",
);
}
let rejectionValue = UNRESOLVED;
try {
await promise;
} catch (e) {
rejectionValue = e;
}
if (rejectionValue !== UNRESOLVED) {
return {
message: () =>
`Expected promise to be fulfilled, but it was rejected with ${rejectionValue}.`,
pass: false,
};
}
return {
message: () =>
'This message should not be displayed as it is for the negative case, which will never happen.',
pass: true,
};
},
/**
* Tests that the given promise is never fulfilled or rejected past a certain
* amount of time (which is the default time that Jest tests wait before

8
types/global.d.ts vendored
View File

@ -7,6 +7,14 @@ declare class Platform {
closeCurrentWindow: () => void;
}
export declare global {
var platform: Platform;
namespace jest {
interface Matchers<R> {
toBeFulfilled(): Promise<R>;
toNeverResolve(): Promise<R>;
}
}
}