diff --git a/app/javascript/packages/analytics/digital-analytics-program.spec.ts b/app/javascript/packages/analytics/digital-analytics-program.spec.ts index f44fcae26e2..e2726a04ee8 100644 --- a/app/javascript/packages/analytics/digital-analytics-program.spec.ts +++ b/app/javascript/packages/analytics/digital-analytics-program.spec.ts @@ -4,12 +4,7 @@ import { pathToFileURL } from 'node:url'; describe('digital analytics program', () => { it('parses without syntax error', async () => { - // Future: Replace with Promise.withResolvers once supported - // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers - let resolve; - const promise = new Promise((_resolve) => { - resolve = _resolve; - }); + const { promise, resolve } = Promise.withResolvers(); // Reference: https://github.com/nodejs/node/issues/30682 const toDataURL = (source: string) => diff --git a/spec/javascript/packages/document-capture/hooks/use-async-spec.jsx b/spec/javascript/packages/document-capture/hooks/use-async-spec.jsx index a1b750a9cb7..4149251c335 100644 --- a/spec/javascript/packages/document-capture/hooks/use-async-spec.jsx +++ b/spec/javascript/packages/document-capture/hooks/use-async-spec.jsx @@ -23,19 +23,8 @@ describe('document-capture/hooks/use-async', () => { } it('returns suspense resource that renders fallback', async () => { - let resolve; - const createPromise = sinon - .stub() - .onCall(0) - .returns( - new Promise((_resolve) => { - resolve = () => { - _resolve(); - }; - }), - ) - .onCall(1) - .throws(); + const { promise, resolve } = Promise.withResolvers(); + const createPromise = sinon.stub().onCall(0).returns(promise).onCall(1).throws(); const { container, findByText } = render(); @@ -47,25 +36,14 @@ describe('document-capture/hooks/use-async', () => { }); it('returns suspense resource that renders error fallback', async () => { - let reject; - const createPromise = sinon - .stub() - .onCall(0) - .returns( - new Promise((_resolve, _reject) => { - reject = () => { - _reject(new Error()); - }; - }), - ) - .onCall(1) - .throws(); + const { promise, reject } = Promise.withResolvers(); + const createPromise = sinon.stub().onCall(0).returns(promise).onCall(1).throws(); const { container, findByText } = render(); expect(container.textContent).to.equal('Loading'); - reject(); + reject(new Error()); expect(await findByText('Error')).to.be.ok(); expect(console).to.have.loggedError();