Testing Strategy for Single Functions

What's the best way to test a single function from a service?

I have a File service:
export class File extends Context.Tag("File")<
  File,
  ReturnType<typeof makeNative>
>() {}


makeNative dependes on globalThis.File:
export class NativeFile extends Context.Tag("NativeFile")<
  NativeFile,
  globalThis.File
>() {}

const makeNative = (file: Effect.Effect.Success<typeof NativeFile>) => ({
  allowOnlyImage: ...,
  maxFileSize: ...,
});


I want to test allowOnlyImage and maxFileSize separately, without the need of providing all their implementations every time:
const result = File.File.pipe(
  Effect.flatMap(({ allowOnlyImage }) => allowOnlyImage),
  Effect.provide(
    Layer.succeed(
      File.File,
      File.File.of({
        /// I want to define 1 function not all
        allowOnlyImage: ...,
      })
    )
  )
);


And possibly also a way to "mock" globalThis.File.

Best strategy here?
Was this page helpful?