@@ -3,6 +3,11 @@ import chaiAsPromised from 'chai-as-promised'
33import sinon from 'sinon'
44import { getConfiguration } from '../src/configuration'
55import { ConnectionManager , connection } from '../src/ConnectionManager'
6+ import {
7+ FortmaticConnector ,
8+ InjectedConnector ,
9+ WalletConnectConnector
10+ } from '../src/connectors'
611import { LocalStorage } from '../src/storage'
712import { ChainId , ClosableConnector , ProviderType } from '../src/types'
813import { StubClosableConnector , StubConnector , StubStorage } from './utils'
@@ -238,6 +243,7 @@ describe('ConnectionManager', () => {
238243 } )
239244
240245 it ( 'should throw if no successful connect occurred' , ( ) => {
246+ connectionManager . connector = undefined
241247 expect ( connectionManager . getProvider ( ) ) . to . eventually . throw (
242248 new Error ( 'No valid connector found. Please .connect() first' )
243249 )
@@ -265,4 +271,40 @@ describe('ConnectionManager', () => {
265271 browser . window = undefined
266272 } )
267273 } )
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+ } )
268310} )
0 commit comments