mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-21 17:37:01 +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:
parent
b43900f743
commit
9c91db5d31
File diff suppressed because it is too large
Load Diff
@ -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
8
types/global.d.ts
vendored
@ -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>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user