Testing Finalizers in Effect Typescript Library

If I want to test finalizers, how I am supposed to do it? I'm doing this, but it is obviously wrong:
  it.scoped('should clean up resources when the service is closed', () =>
    Effect
      .gen(function*() {
        // the service, which will be automatically cleaned up when the scoped test completes
        const service = yield* WhatsappService;

        // Add a finalizer to check if destroy is called
        yield* Effect.addFinalizer(() =>
          Effect.sync(() => {
            // This will be called when the scope is closed
            expect(mockClient.destroy).toHaveBeenCalled();
          })
        );
      })
      .pipe(deps));

My finalizer is being called before the one defined inside the service
Was this page helpful?