I have this case where I want to test a function with some specific this
. But typescript either won't let me add the method to the object, or if I define it as any
then my interface is not being used.
example:
import getMostPeersTorrentsFromDateRange from './index'
import Db from '../Db'
test('getMostPeersTorrentsFromDateRange', async () => {
const db = Db() as any
db.getMostPeersTorrentsFromDateRange = getMostPeersTorrentsFromDateRange
const torrents = await db.getMostPeersTorrentsFromDateRange({startDate: '2019-03-03', endDate: '2019-03-08', limit: 100})
})
and in the other file
import {Torrent} from '../interfaces'
interface GetMostPeersTorrentsFromDateRange {
(GetMostPeersTorrentsFromDateRangeSettings: {
startDate: string,
endDate: string,
limit: number
}): Promise<Torrent[]>
}
const getMostPeersTorrentsFromDateRange: GetMostPeersTorrentsFromDateRange = async function ({startDate, endDate, limit}) {
return []
}
export default getMostPeersTorrentsFromDateRange
How can I achieve what I'm trying to do with the least amount of code repetition? I don't want to define getMostPeersTorrentsFromDateRange
twice, and I don't really want to import/export it either.