Mocking Dependencies in Tests for NotificationApi

Does anyone have a foolproof way of mocking dependencies in tests?

I want to ignore any dependencies that NotificationApi requires as I am just need to mock the functions it provides. I don't care about it's dependencies

 yield* userApi.createUser({
        name
      }).pipe(
        Effect.provide(
          makeTestLayer(UserRepo)({
            getById: () => Effect.succeed(undefined),
          }),
        ),
        // This throws an error 
        // Type 'NotificationRepo' is not assignable to type 'UserApi
        // I need to be able to simply provide a mock of the NotificationApi
        // And ignore any dependencies that it expects
        Effect.provide(
          makeTestLayer(NotificationApi)({
            sendNotification: () => Effect.succeed("ok"),
          }),
        ),
    )
    }),


// The makeTestLayer functon comes from effect-http-play: https://github.com/tim-smart/effect-http-play/blob/main/src/lib/Layer.ts
Was this page helpful?