You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if withFileTypes is true, the return type of calls to readdir is Promise<Dirent[]> otherwise the return type is Promise<string[]>
import{readdir}from'fs/promises'vi.mock('fs')constmockReaddir=vi.mocked(readdir)// the below will throw a typescript errormockReaddir.mockReaddir.mockResolvedValueOnce(['a','b'])// the below will NOT throw a typescript errormockReaddir.mockReaddir.mockResolvedValueOnce(['a','b']asunknownasDirent[])
currently, vi.mocked narrows down to the Dirent version by default. thus, here is the current workaround i'm using
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i'm looking for suggestions on using the
mocked
helper with functions which have multiple signaturesas an example, readdir from node's
fs/promises
module supports multiple signatures that are discriminated byoptions.withFileTypes
if
withFileTypes
istrue
, the return type of calls toreaddir
isPromise<Dirent[]>
otherwise the return type isPromise<string[]>
currently,
vi.mocked
narrows down to theDirent
version by default. thus, here is the current workaround i'm usingBeta Was this translation helpful? Give feedback.
All reactions