(instance: any | any[], expectedValues: any | any[])
| 4 | * Compares instance with expected values |
| 5 | */ |
| 6 | export function assertInstance(instance: any | any[], expectedValues: any | any[]): void { |
| 7 | if (Array.isArray(expectedValues)) { |
| 8 | expect(instance).to.have.property('length', expectedValues.length); |
| 9 | |
| 10 | return instance.forEach((_instance, i) => assertInstance(_instance, expectedValues[i])); |
| 11 | } |
| 12 | |
| 13 | expect(instance).to.have.property('id').that.is.not.null; |
| 14 | |
| 15 | Object.keys(expectedValues).forEach((key) => { |
| 16 | const value = instance[key]; |
| 17 | const expectedValue = expectedValues[key]; |
| 18 | |
| 19 | expect(instance).to.have.property(key).that.is.not.null.and.not.undefined; |
| 20 | |
| 21 | if (typeof expectedValue === 'object') { |
| 22 | assertInstance(value, expectedValue); |
| 23 | } else { |
| 24 | expect(instance).to.have.property(key, expectedValue); |
| 25 | } |
| 26 | }); |
| 27 | } |
no outgoing calls
searching dependent graphs…