Skip to content

Commit

Permalink
test: createConfig restore unconfigured chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 29, 2024
1 parent fbe21fe commit 8b22591
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/core/src/createConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,46 @@ test('behavior: properties passed through to Viem Client via getClient', () => {
`)
}
})

test('behavior: restore unconfigured chainId', () => {
const state = {
'wagmi.store': JSON.stringify({
state: { chainId: 10 },
version: 1,
}),
} as Record<string, string>
Object.defineProperty(window, 'localStorage', {
value: {
getItem: vi.fn((key) => state[key] ?? null),
removeItem: vi.fn((key) => state.delete?.[key]),
setItem: vi.fn((key, value) => {
state[key] = value
}),
},
writable: true,
})

const storage = createStorage<{ store: object }>({
storage: window.localStorage,
})

const config = createConfig({
chains: [mainnet],
storage,
transports: {
[mainnet.id]: http(),
},
})

expect(config.state).toMatchInlineSnapshot(`
{
"chainId": 1,
"connections": Map {},
"current": null,
"status": "disconnected",
}
`)

const client = config.getClient()
expect(client.chain.id).toBe(mainnet.id)
})

0 comments on commit 8b22591

Please sign in to comment.