fix broken tests · dev-protocol/dev-elements@3b64a9b · GitHub
Skip to content

Commit 3b64a9b

Browse files
committed
fix broken tests
1 parent bc83910 commit 3b64a9b

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions

‎src/dev-connection/index.test.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai'
2-
import { ethers } from 'ethers'
2+
import { ethers } from 'bundled-ethers'
33
import { Connection } from './index'
44
import { define } from '@aggre/ullr'
55
import { html, render } from 'lit'
@@ -46,7 +46,7 @@ describe('dev-connection', () => {
4646
)
4747
el.signer.next(mock)
4848

49-
await waitForUpdated(el.account.asObservable())
49+
await waitForUpdated(el.account)
5050
expect(el.account.getValue()).to.be.equal(await mock.getAddress())
5151
})
5252
it('when signer is changed to undefined, account will update to undefined', async () => {
@@ -56,11 +56,11 @@ describe('dev-connection', () => {
5656
new ethers.providers.JsonRpcProvider(rpcEndpoints[0])
5757
)
5858
el.signer.next(mock)
59-
await waitForUpdated(el.account.asObservable())
59+
await waitForUpdated(el.account)
6060

6161
el.signer.next(undefined)
6262

63-
await waitForUpdated(el.account.asObservable())
63+
await waitForUpdated(el.account)
6464
expect(el.account.getValue()).to.be.equal(undefined)
6565
})
6666
it('when signer is changed to undefined, provider will update to undefined', async () => {
@@ -128,7 +128,7 @@ describe('dev-connection', () => {
128128
await waitForUpdated(el.chain.pipe(filter((x) => x !== undefined)))
129129
expect(el.chain.getValue()).to.be.equal(42161)
130130
})
131-
it('when provider is changed to undefined, chain and signer will update to undefined', async () => {
131+
it('when provider is changed to undefined, chain will update to undefined', async () => {
132132
const el = connection()
133133
const mock = new ethers.providers.JsonRpcProvider(rpcEndpoints[0])
134134
el.provider.next(mock)
@@ -140,7 +140,6 @@ describe('dev-connection', () => {
140140
await waitForUpdated(el.chain.pipe(filter((x) => x === undefined)))
141141

142142
expect(el.chain.getValue()).to.be.equal(undefined)
143-
expect(el.signer.getValue()).to.be.equal(undefined)
144143
})
145144
})
146145
})

‎src/dev-connection/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class Connection extends UllrElement {
7575
} else {
7676
this.provider.next(undefined)
7777
}
78-
x.getAddress().then(this.account.next)
78+
x.getAddress().then((addr) => this.account.next(addr))
7979
})
8080

8181
this._providerSubscription = this.provider.asObservable().subscribe((x) => {

‎src/lib/test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable functional/no-conditional-statement */
44
/* eslint-disable functional/no-expression-statement */
55
import type { UndefinedOr } from '@devprotocol/util-ts'
6-
import { Observable, take } from 'rxjs'
6+
import { distinctUntilChanged, Observable, take } from 'rxjs'
77

88
export const sleep = async (time: number): Promise<void> =>
99
new Promise(
@@ -56,4 +56,6 @@ export const rpcEndpoints = [
5656
]
5757

5858
export const waitForUpdated = <T>(obs: Observable<T>) =>
59-
new Promise<T>((res) => obs.pipe(take(1)).subscribe(res))
59+
new Promise<T>((res) =>
60+
obs.pipe(distinctUntilChanged(), take(1)).subscribe(res)
61+
)

‎yarn.lock‎

Lines changed: 20 additions & 3 deletions

0 commit comments

Comments
 (0)