mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 12:37:00 +03:00
add tests, new partialDeepEquals
This commit is contained in:
@@ -7,4 +7,20 @@ export function getbaseURL(): string {
|
||||
/**
|
||||
* Duplicated from Mocha types. TypeScript doesn't infer that type by itself for some reason.
|
||||
*/
|
||||
export type Done = (err?: any) => void;
|
||||
export type Done = (err?: any) => void;
|
||||
|
||||
/**
|
||||
*
|
||||
* Check object contains expected properties
|
||||
*/
|
||||
export const partialDeepEquals = (actual: Record<string, any>, expected: Record<string, any>): boolean => {
|
||||
// loop over key, value of expected
|
||||
for (const [ key, value ] of Object.entries(expected)) {
|
||||
// if value is object or array, recurse
|
||||
if (Array.isArray(value) || typeof value === "object") {
|
||||
if (!partialDeepEquals(actual?.[key], value)) return false;
|
||||
}
|
||||
else if (actual?.[key] !== value) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user