MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / assertDeepEqual

Function assertDeepEqual

apps/automated/src/tk-unit.ts:206–260  ·  view source on GitHub ↗
(actual, expected, message: string = '', path: any[] = [])

Source from the content-addressed store, hash-verified

204 * Assert two json like objects are deep equal.
205 */
206export function assertDeepEqual(actual, expected, message: string = '', path: any[] = []): void {
207 let typeofActual: string = typeof actual;
208 let typeofExpected: string = typeof expected;
209 if (typeofActual !== typeofExpected) {
210 throw new Error(message + ' ' + 'At /' + path.join('/') + ' types of actual ' + typeofActual + ' and expected ' + typeofExpected + ' differ.');
211 } else if (typeofActual === 'object' || typeofActual === 'array') {
212 if (expected instanceof Map) {
213 if (actual instanceof Map) {
214 expected.forEach((value, key) => {
215 if (actual.has(key)) {
216 assertDeepEqual(actual.get(key), value, message, path.concat([key]));
217 } else {
218 throw new Error(message + ' ' + 'At /' + path.join('/') + " expected Map has key '" + key + "' but actual does not.");
219 }
220 });
221 actual.forEach((value, key) => {
222 if (!expected.has(key)) {
223 throw new Error(message + ' ' + 'At /' + path.join('/') + " actual Map has key '" + key + "' but expected does not.");
224 }
225 });
226 } else {
227 throw new Error(message + ' ' + 'At /' + path.join('/') + ' expected is Map but actual is not.');
228 }
229 }
230 if (expected instanceof Set) {
231 if (actual instanceof Set) {
232 expected.forEach((i) => {
233 if (!actual.has(i)) {
234 throw new Error(message + ' ' + 'At /' + path.join('/') + " expected Set has item '" + i + "' but actual does not.");
235 }
236 });
237 actual.forEach((i) => {
238 if (!expected.has(i)) {
239 throw new Error(message + ' ' + 'At /' + path.join('/') + " actual Set has item '" + i + "' but expected does not.");
240 }
241 });
242 } else {
243 throw new Error(message + ' ' + 'At /' + path.join('/') + ' expected is Set but actual is not.');
244 }
245 }
246 for (let key in actual) {
247 if (!(key in expected)) {
248 throw new Error(message + ' ' + 'At /' + path.join('/') + ' found unexpected key ' + key + '.');
249 }
250 assertDeepEqual(actual[key], expected[key], message, path.concat([key]));
251 }
252 for (let key in expected) {
253 if (!(key in actual)) {
254 throw new Error(message + ' ' + 'At /' + path.join('/') + ' expected a key ' + key + '.');
255 }
256 }
257 } else if (actual !== expected) {
258 throw new Error(message + ' ' + 'At /' + path.join('/') + " actual: '" + actual + "' and expected: '" + expected + "' differ.");
259 }
260}
261
262export function assertDeepSuperset(actual, expected, path: any[] = []): void {
263 let typeofActual: string = typeof actual;

Callers

nothing calls this directly

Calls 4

joinMethod · 0.80
forEachMethod · 0.80
concatMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected