import * as React from 'react' ; import { renderHook } from '@testing-library/react-hooks' ; import { ApiHostProvider , useHost } from '..' ; describe ( 'ApiHostProvider and useHost' , ( ) => { it ( 'should default to null if no host provided' , ( ) => { const { result } = renderHook ( useHost ) ; expect ( result . current ) . toBe ( null ) ; } ) ; it ( 'should allow a hostname to be unset' , ( ) => { const wrapper = ( { children } ) => ( < ApiHostProvider hostname = { null } > { children } < /ApiHostProvider>); const { result } = renderHook ( useHost , { wrapper } ) ; expect ( result . current ) . toBe ( null ) ; } ) ; it ( 'should allow a hostname to be set' , ( ) => { const wrapper = ( { children } ) => ( < ApiHostProvider hostname = "localhost" > { children } < /ApiHostProvider>); const { result } = renderHook ( useHost , { wrapper } ) ; expect ( result . current ) . toEqual ( { hostname : 'localhost' , port : null } ) ; } ) ; it ( 'should allow a port to be set' , ( ) => { const wrapper = ( { children } ) => ( < ApiHostProvider hostname = "127.0.0.1" port = { 31950 } > { children } < /ApiHostProvider>); const { result } = renderHook ( useHost , { wrapper } ) ; expect ( result . current ) . toEqual ( { hostname : '127.0.0.1' , port : 31950 } ) ; } ) ; } ) ;