diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 5c94d871b1d..1e71fdcd17f 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -206,15 +206,21 @@ function runTests(backend: string, initCrypto: InitCrypto, methods: string[] | u short_authentication_string: ["decimal", "emoji"], }, }); - await waitForVerificationRequestChanged(request); - expect(request.phase).toEqual(VerificationPhase.Started); - expect(request.otherPartySupportsMethod("m.sas.v1")).toBe(true); - expect(request.chosenMethod).toEqual("m.sas.v1"); - - // there should now be a verifier - const verifier: Verifier = request.verifier!; - expect(verifier).toBeDefined(); - expect(verifier.getShowSasCallbacks()).toBeNull(); + // as soon as the Changed event arrives, `verifier` should be defined + const verifier = await new Promise((resolve) => { + function onChange() { + expect(request.phase).toEqual(VerificationPhase.Started); + expect(request.otherPartySupportsMethod("m.sas.v1")).toBe(true); + expect(request.chosenMethod).toEqual("m.sas.v1"); + + const verifier: Verifier = request.verifier!; + expect(verifier).toBeDefined(); + expect(verifier.getShowSasCallbacks()).toBeNull(); + + resolve(verifier); + } + request.once(VerificationRequestEvent.Change, onChange); + }); // start off the verification process: alice will send an `accept` const sendToDevicePromise = expectSendToDeviceMessage("m.key.verification.accept"); diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index b9dfe6e4aa4..f4c8f3697fd 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -47,8 +47,6 @@ export class RustVerificationRequest super(); const onChange = async (): Promise => { - this.emit(VerificationRequestEvent.Change); - // if we now have a `Verification` where we lacked one before, wrap it. // TODO: QR support if (this._verifier === undefined) { @@ -57,6 +55,8 @@ export class RustVerificationRequest this._verifier = new RustSASVerifier(verification, this, outgoingRequestProcessor); } } + + this.emit(VerificationRequestEvent.Change); }; inner.registerChangesCallback(onChange); }