add tests, new partialDeepEquals

This commit is contained in:
Michael C
2021-08-02 02:47:49 -04:00
parent 31a7838851
commit b39c06a9ef
2 changed files with 151 additions and 1 deletions

View File

@@ -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;
};