-
Notifications
You must be signed in to change notification settings - Fork 970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Tests since MWA is no longer autoselected #1021
base: revert-1012
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,9 +219,9 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
adapters.push(customAdapter); | ||
jest.clearAllMocks(); | ||
}); | ||
it('loads the custom mobile wallet adapter into state as the default', () => { | ||
it('does not load the custom mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter).toBe(customAdapter); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter).toBe(undefined); | ||
}); | ||
it('does not construct any further mobile wallet adapters', () => { | ||
renderTest({}); | ||
|
@@ -232,9 +232,9 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
beforeEach(() => { | ||
localStorage.removeItem(WALLET_NAME_CACHE_KEY); | ||
}); | ||
it('loads the mobile wallet adapter into state as the default', () => { | ||
it('does not load the mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter.name).toBe(SolanaMobileWalletAdapterWalletName); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter.name).toBe(undefined); | ||
}); | ||
it('loads no public key into state', () => { | ||
renderTest({}); | ||
|
@@ -326,10 +326,14 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
describe('onError', () => { | ||
let onError: jest.Mock; | ||
let errorThrown: WalletError; | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
errorThrown = new WalletError('o no'); | ||
onError = jest.fn(); | ||
renderTest({ onError }); | ||
await act(async () => { | ||
ref.current?.getWalletContextState().select(SolanaMobileWalletAdapterWalletName); | ||
await Promise.resolve(); // Flush all promises in effects after calling `select()`. | ||
}); | ||
Comment on lines
+341
to
+348
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change doesn't make sense to me. MWA shouldn't be deselected after each test, given the comment following this one) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey sorry, not sure I totally follow – I don't think there's any selecting involved, the test is just to make sure that when the adapter emits an error, it expects |
||
}); | ||
describe('when the wallet emits an error', () => { | ||
let adapter: Adapter; | ||
|
@@ -452,8 +456,8 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
mobileWalletAdapter.disconnect(); | ||
}); | ||
}); | ||
it('should not clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).not.toHaveBeenCalled(); | ||
it('should clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('when window beforeunload event fires', () => { | ||
|
@@ -470,8 +474,8 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
mobileWalletAdapter.disconnect(); | ||
}); | ||
}); | ||
it('should not clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).not.toHaveBeenCalled(); | ||
it('should clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).toHaveBeenCalled(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I think the original intent of the test is correct -- the wallet disconnecting should NOT deselect the wallet or remove it from LocalStorage, because then autoconnect will be broken on reload. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this true? AFAICT when using wallet adapter, autoconnect is not supposed to reload the last used wallet if disconnect was called |
||
}); | ||
it('should clear out the state', () => { | ||
expect(ref.current?.getWalletContextState()).toMatchObject({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead tests need to be changed/added such that
I think this satisfies the intent of the new code this is targeting.