Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

darky/klubok

Repository files navigation

Klubok

Do notation pipes for Promise-based or pure functions which easy to mock
Inspired by fp-ts/Effect bind Do-notation, but much more small and simple
Primarly created for easy mocking of functions, which allows to write tons of unit tests using London school approach

Example

{ /* fetch cats from DB */ }), pure('catsOneYearOld', ({ cats }) => cats.map(cat => ({ ...cat, age: cat.age + 1 })), eff('saved', async ({ catsOneYearOld }) => { /* save to DB */ }) ) // production usage catsBirthdays({ ids: [1, 2, 3] }) // in tests usage catsBirthdays( { ids: [1, 2, 3] }, { // DB response mock cats: () => [ { name: 'Barsik', age: 10 }, { name: 'Marfa', age: 7 } ] }, // call only this functions ['catsOneYearOld'] ) // Promise<{ ..., catsOneYearOld: [{ name: 'Barsik', age: 11 }, { name: 'Marfa', age: 8 }] }> ">import { pure, eff, klubok } from 'klubok';

const catsBirthdays = klubok(
eff('cats', async ({ ids }: { ids: number[] }) => { /* fetch cats from DB */ }),

pure('catsOneYearOld', ({ cats }) => cats.map(cat => ({ ...cat, age: cat.age + 1 })),

eff('saved', async ({ catsOneYearOld }) => { /* save to DB */ })
)

// production usage
catsBirthdays({ ids: [1, 2, 3] })

// in tests usage
catsBirthdays(
{ ids: [1, 2, 3] },

{
// DB response mock
cats: () => [
{ name: 'Barsik', age: 10 },
{ name: 'Marfa', age: 7 }
]
},

// call only this functions
['catsOneYearOld']

) // Promise<{ ..., catsOneYearOld: [{ name: 'Barsik', age: 11 }, { name: 'Marfa', age: 8 }] }>

See also

About

Do notation pipes for Promise-based or pure functions which easy to mock

Topics

Resources

Readme

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors