import * as $ from 'jquery' ; import { match , SinonMatcher } from 'sinon' ; import * as VError from 'verror' ; param { Error | string } error returns { Sinon . SinonMatcher } export function matchesError ( error ) { const errorMessage = getErrorMessage ( error ) ; return match ( ( actual ) => actual . message === errorMessage , errorMessage ) ; } param { Error | string } cause returns { Sinon . SinonMatcher } export function matchesCause ( cause ) { const errorMessage = getErrorMessage ( cause ) ; return match ( ( actual ) => actual . cause ( ) && actual . cause ( ) . message === errorMessage , errorMessage ) ; } param { JQuery < HTMLElement > } elements returns { Sinon . SinonMatcher } export function matchesElements ( elements ) { const message = 'should only select elements: ' + `\n${ $ . map ( elements , ( element ) => element . outerHTML ) . join ( ',\n' ) }\n` ; return match ( ( selector ) => { const selected = $ ( selector ) ; return ( selected . length === elements . length ) && $ . map ( elements , ( e ) => selected . is ( e ) ) . every ( Boolean ) ; } , message ) ; } function getErrorMessage ( error ) { return ( typeof error === 'string' ) ? error : error . message ; }