2022-03-28 16:00:42 +02:00
|
|
|
import { webcrypto } from "crypto";
|
|
|
|
|
2023-05-09 11:27:09 +02:00
|
|
|
import { toEqualBuffer } from "./spec";
|
2024-03-27 18:03:09 +01:00
|
|
|
import { toAlmostEqual } from "./spec/matchers/to-almost-equal";
|
2022-07-26 03:40:32 +02:00
|
|
|
|
2022-03-28 16:00:42 +02:00
|
|
|
Object.defineProperty(window, "crypto", {
|
|
|
|
value: webcrypto,
|
|
|
|
});
|
2022-07-26 03:40:32 +02:00
|
|
|
|
|
|
|
// Add custom matchers
|
|
|
|
|
|
|
|
expect.extend({
|
|
|
|
toEqualBuffer: toEqualBuffer,
|
2024-03-27 18:03:09 +01:00
|
|
|
toAlmostEqual: toAlmostEqual,
|
2022-07-26 03:40:32 +02:00
|
|
|
});
|
|
|
|
|
2023-08-04 04:13:33 +02:00
|
|
|
export interface CustomMatchers<R = unknown> {
|
2022-07-26 03:40:32 +02:00
|
|
|
toEqualBuffer(expected: Uint8Array | ArrayBuffer): R;
|
2024-03-27 18:03:09 +01:00
|
|
|
/**
|
|
|
|
* Matches the expected date within an optional ms precision
|
|
|
|
* @param expected The expected date
|
|
|
|
* @param msPrecision The optional precision in milliseconds
|
|
|
|
*/
|
|
|
|
toAlmostEqual(expected: Date, msPrecision?: number): R;
|
2022-07-26 03:40:32 +02:00
|
|
|
}
|