@@ -3,6 +3,11 @@ import chaiAsPromised from 'chai-as-promised'
3
3
import sinon from 'sinon'
4
4
import { getConfiguration } from '../src/configuration'
5
5
import { ConnectionManager , connection } from '../src/ConnectionManager'
6
+ import {
7
+ FortmaticConnector ,
8
+ InjectedConnector ,
9
+ WalletConnectConnector
10
+ } from '../src/connectors'
6
11
import { LocalStorage } from '../src/storage'
7
12
import { ChainId , ClosableConnector , ProviderType } from '../src/types'
8
13
import { StubClosableConnector , StubConnector , StubStorage } from './utils'
@@ -238,6 +243,7 @@ describe('ConnectionManager', () => {
238
243
} )
239
244
240
245
it ( 'should throw if no successful connect occurred' , ( ) => {
246
+ connectionManager . connector = undefined
241
247
expect ( connectionManager . getProvider ( ) ) . to . eventually . throw (
242
248
new Error ( 'No valid connector found. Please .connect() first' )
243
249
)
@@ -265,4 +271,40 @@ describe('ConnectionManager', () => {
265
271
browser . window = undefined
266
272
} )
267
273
} )
274
+
275
+ describe ( '#getConnector' , ( ) => {
276
+ it ( 'should throw if an invalid provider type is supplied' , ( ) => {
277
+ const providerType = 'Invalid Provider Type' as any
278
+ expect ( ( ) =>
279
+ connectionManager . getConnector ( providerType , ChainId . MAINNET )
280
+ ) . to . throw ( `Invalid provider ${ providerType } ` )
281
+ } )
282
+
283
+ it ( 'should return an instance of FortmaticConnector for the supplied chain' , ( ) => {
284
+ const connector = connectionManager . getConnector (
285
+ ProviderType . FORTMATIC ,
286
+ ChainId . KOVAN
287
+ )
288
+ expect ( connector ) . to . be . instanceOf ( FortmaticConnector )
289
+ expect ( connector . getChainId ( ) ) . to . eventually . eq ( ChainId . KOVAN )
290
+ } )
291
+
292
+ it ( 'should return an instance of InjectedConnector for the supplied chain' , ( ) => {
293
+ const connector = connectionManager . getConnector (
294
+ ProviderType . INJECTED ,
295
+ ChainId . KOVAN
296
+ )
297
+ expect ( connector ) . to . be . instanceOf ( InjectedConnector )
298
+ expect ( connector . getChainId ( ) ) . to . eventually . eq ( ChainId . KOVAN )
299
+ } )
300
+
301
+ it ( 'should return an instance of WalletConnectConnector for the supplied chain' , ( ) => {
302
+ const connector = connectionManager . getConnector (
303
+ ProviderType . WALLET_CONNECT ,
304
+ ChainId . KOVAN
305
+ )
306
+ expect ( connector ) . to . be . instanceOf ( WalletConnectConnector )
307
+ expect ( connector . getChainId ( ) ) . to . eventually . eq ( ChainId . KOVAN )
308
+ } )
309
+ } )
268
310
} )
0 commit comments