| 260 | } |
| 261 | |
| 262 | export function assertDeepSuperset(actual, expected, path: any[] = []): void { |
| 263 | let typeofActual: string = typeof actual; |
| 264 | let typeofExpected: string = typeof expected; |
| 265 | if (typeofActual !== typeofExpected) { |
| 266 | throw new Error('At /' + path.join('/') + ' types of actual ' + typeofActual + ' and expected ' + typeofExpected + ' differ.'); |
| 267 | } else if (typeofActual === 'object' || typeofActual === 'array') { |
| 268 | for (let key in expected) { |
| 269 | if (!(key in actual)) { |
| 270 | throw new Error('At /' + path.join('/') + ' expected a key ' + key + '.'); |
| 271 | } |
| 272 | assertDeepSuperset(actual[key], expected[key], path.concat([key])); |
| 273 | } |
| 274 | } else if (actual !== expected) { |
| 275 | throw new Error('At /' + path.join('/') + " actual: '" + actual + "' and expected: '" + expected + "' differ."); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | export function assertNull(actual: any, message?: string) { |
| 280 | if (actual !== null && actual !== undefined) { |