mocks-for-everyone

0.1.1 • Public • Published

Usage

Screenshot from 2024-03-14 20-51-11

  • Click on the bottom left arrow to open the mock list.
  • Select all mocks that you want to intercept.
  • Reload page to apply the changes.
  • Enjoy!! All requests that are intercepted will be returned with the mock data.

Install

  • Install this package in your project

  • Add init mock service work function to intercept requests initMockServiceWorker() in your index, for example:

    // Init intercept requests (using service worker) to mock requests
    // just in development or staging environment
    if (env !== 'production') {
       const objMocks:GroupMockDebug[] = {YOUR MOCKS IN HERE};
    
       initMockServiceWorker(objMocks);
    }
    
    // here your React render, it is just a e.g.
    ReactDOM.render(
       <React.StrictMode>
           <App />
       </React.StrictMode>,
       document.getElementById('root')
    );
    
    • the first param is a type GroupMockDebug[] with all mocks do has
    • you can organize mocks with title inside your array GroupMockDebug[]
    • will intercept only mocks selected.
    • obs: don't init in production environment
  • Add component in your project to you can select what to mock

    •  const groupMockDebugsMock:GroupMockDebug[] = `YOUR MOCKS IN HERE`;
       
       <SelectMockContainer render={env !== 'production'} mocks={groupMockDebugsMock}>
      
  • Add Service Worker

    • Create a file mockServiceWorker.js in the root from folter public, it need to stay in the root of your application.
    • Add this code in file you create mockServiceWorker.js: self.importScripts('https://truepay-mocks.web.app/mockServiceWorker.js');
  • When you init your application, you can click on bottom left arrow to open the mock list. If it doesn't have a value selected, it won't be intercepted.

Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 <script setup> SFCs, check out the script setup docs to learn more.

Recommended IDE Setup

Type Support For .vue Imports in TS

TypeScript cannot handle type information for .vue imports by default, so we replace the tsc CLI with vue-tsc for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:

  1. Disable the built-in TypeScript Extension
    1. Run Extensions: Show Built-in Extensions from VSCode's command palette
    2. Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace)
  2. Reload the VSCode window by running Developer: Reload Window from the command palette.

Readme

Keywords

none

Package Sidebar

Install

npm i mocks-for-everyone

Weekly Downloads

0

Version

0.1.1

License

ISC

Unpacked Size

44.3 kB

Total Files

39

Last publish

Collaborators

  • luanluanluan