question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rename "composeMocks" to better describe what it does

See original GitHub issue

Is your feature request related to a problem? Please describe.

I find it confusing that composeMocks() function composes request handlers, and not mocks.

Describe the solution you’d like I think renaming composeMocks() function to composeHandlers() would provide a more domain-driven name, and won’t confuse the users.

- const { start } = composeMocks(...)
+ const { start } = composeHandlers(...)

Benefits of the change

  • Aligned with the internal vocabulary
  • Function does exactly what it’s called after

Drawbacks of the change

  • Longer to write
  • Not straight intuitive if you don’t know the library’s glossary

Alternatives to consider I was also thinking about simply naming it compose(), but I’m afraid this will clash with the similar functional composition utility that is often called compose(). Also, composeMocks() is not the traditional compose function per-say, as it’s logic is specific to MSW.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
andreawysscommented, Apr 24, 2020
// Browser usage
import { setupServiceWorker } from 'msw'

const { start, stop } = setupServiceWorker(options)
start()

// Node usage
import { setupMockServer } from 'msw'

setupMockServer(options)
2reactions
kettanaitocommented, Apr 24, 2020

As MSW will eventually support mocking in non-browser environments, I think that such initializer functions like composeMocks() should clearly describe what are they initializing.

I suggest the following API:

useWorker()

function useWorker(...handlers: RequestHandler[]): WorkerAPI

Uses a Service Worker with the given request handlers.

useServer()

function useServer(...handlers: RequestHandler[]): unknown

Stubs an XHR communication with the given request handlers, thus, mimicking a server.

I’m not found of a word “server” where there are no actual servers, so please feel free to share what name makes more sense to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

msw: Versions - Openbase
Full version history for msw including change logs.
Read more >
Untitled
Define purging storage, Pastor luna chamame maceta, Cherish the ladies an irish ... Best amp for headphone practice, Raonsims hair 46, Surheide bremerhaven, ......
Read more >
The msw from mswjs - Mock Service Worker
Mock Service Worker (MSW) is a seamless REST/GraphQL API mocking library for browser and Node.js. ... Rename "composeMocks" to better describe what it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found