angular/packages/bazel/test/ng_package/test_utils.ts
Kristiyan Kostadinov 41223a81f2 build: update to jasmine 4.0 (#45558)
Updates us to version 4.0 of Jasmine and fixes some errors that were the result of us depending upon deprecated APIs. We need to do this both to stay up to date and because it was going to break eventually, because one of the Bazel packages was logging a deprecation warning that version 4.0 was required.

There were also some cases where the state of `ngDevMode` had started leaking out between tests.

PR Close #45558
2022-04-11 16:25:28 +00:00

25 lines
919 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* Jasmine asymmetric matcher that compares a given object ensuring that it matches deep
* with the other while also respecting the order of keys. This is useful when comparing
* the NodeJS `package.json` `exports` field where order matters.
*/
export function matchesObjectWithOrder(expected: any): jasmine.AsymmetricMatcher<any> {
return {
asymmetricMatch(actual: any): boolean {
// Use JSON stringify to compare the object with respect to the order of keys
// in the object, and its nested objects.
return JSON.stringify(actual) === JSON.stringify(expected);
},
jasmineToString(prettyPrint: (value: any) => string): string {
return prettyPrint(expected);
}
};
}