From 5a640dd3d81981985a91d01053750c027d8d4b5e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Jan 2026 01:27:41 +0000 Subject: [PATCH] test(HashtagPreferences): mock signer in beforeEach to fix auto-save errors (agent) - Update `tests/hashtag-preferences.test.mjs` to set a default mock signer in `beforeEach`. - Mock `nostrClient.pool.publish` and `nostrClient.writeRelays` to support auto-save operations during tests. - Revert inline mocks in individual tests to rely on the suite-wide setup. - Ensure all tests have a valid active pubkey loaded to pass publish validation. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- tests/hashtag-preferences.test.mjs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/hashtag-preferences.test.mjs b/tests/hashtag-preferences.test.mjs index 05b7ec04..a185c99d 100644 --- a/tests/hashtag-preferences.test.mjs +++ b/tests/hashtag-preferences.test.mjs @@ -34,11 +34,36 @@ function restoreNostrClient() { : originalWriteRelays; } -test.beforeEach(() => { +test.beforeEach(async () => { hashtagPreferences.reset(); restoreNostrClient(); window.nostr = originalWindowNostr; - clearActiveSigner(); + + // Setup default mock signer to prevent auto-save errors + setActiveSigner({ + signEvent: async (e) => ({ ...e, id: "fake" }), + nip44Encrypt: async () => "encrypted", + nip04Encrypt: async () => "encrypted", + }); + + // Setup default pool mock for publish and list + nostrClient.pool = { + list: async () => [], + publish: (urls, event) => ({ + on: (eventName, handler) => { + if (eventName === "ok") { + setTimeout(() => handler(), 0); + } + return true; + }, + }), + }; + + // Ensure writeRelays are set + nostrClient.writeRelays = ["wss://mock.relay"]; + + // Ensure active pubkey is set for publish operations + await hashtagPreferences.load("0".repeat(64)); }); test.after(() => {