nx/packages/angular/testing/src/testing-utils.ts
Leosvel Pérez Espinosa e01189230c
feat(angular): deprecate data persistence operators (#27401)
- Deprecate the `@nx/angular` data persistence operators in favor of
importing them from `@ngrx/router-store/data-persistence`. The operator
will be removed from the `@nx/angular` package in Nx v21.
- Update the deprecation message for `@nx/angular/testing` helpers to
communicate that they will be removed in Nx v21.

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-08-13 14:44:03 +02:00

41 lines
1.2 KiB
TypeScript

import type { Observable } from 'rxjs';
import { first, toArray } from 'rxjs/operators';
/**
* @deprecated This will be removed in Nx v21. If using RxJS 7, use `firstValueFrom(obs$.pipe(toArray()))`
* or `lastValueFrom(obs$.pipe(toArray()))`. If using RxJS 6, use `obs$.pipe(toArray()).toPromise()`.
*
* @whatItDoes reads all the values from an observable and returns a promise
* with an array of all values. This should be used in combination with async/await.
*
* ## Example
*
* ```typescript
* const obs = of(1, 2, 3, 4);
* const res = await readAll(obs)
* expect(res).toEqual([1, 2, 3, 4]);
* ```
*/
export function readAll<T>(o: Observable<T>): Promise<T[]> {
return o.pipe(toArray()).toPromise();
}
/**
* @deprecated This will be removed in Nx v21. Since RxJS 7, use `firstValueFrom(obs$)`. If using RxJS 6,
* use `obs$.pipe(first()).toPromise()`.
*
* @whatItDoes reads the first value from an observable and returns a promise
* with it. This should be used in combination with async/await.
*
* ## Example
*
* ```typescript
* const obs = of(1, 2, 3, 4);
* const res = await readFirst(obs)
* expect(res).toEqual(1);
* ```
*/
export function readFirst<T>(o: Observable<T>): Promise<T> {
return o.pipe(first()).toPromise();
}