1.0.1 • Published 2 years ago

mock-component-generator v1.0.1

Weekly downloads
12
License
MIT
Repository
github
Last release
2 years ago

mock-component-generator

Generate a __mock__ folder with mocks for all jsx and tsx files that match the glob. Per default existing __mocks__ will not be overwritten. Currently all components (class and functional) will be mocked as function.

oclif Version Downloads/week License

Usage

$ npm install -g mock-component-generator
$ cd my-folder
$ generateMockComponents **/foo/bar.*
...generating mocks

Options

--keepImports (-i): Keep the imports. Default is false

--keepTSTypes (-t): Keep the TS-Types. Default is false

Example.

Running

generateMockComponents **/foo.*

in

|- foo.tsx
|- ComponentA.tsx
|- ComponentB.jsx
|- OtherStuff.ts

|- subfolder
  |- foo.js

will result in

|- __mocks__
  |- foo.tsx


|- ComponentA.tsx
|- ComponentB.jsx
|- OtherStuff.ts

|- subfolder
  |- __mocks__
    |- foo.js
  |- foo.js

where

import React from 'react'
import { foo } from 'bar'

export const HelloComponent = (props: { name: string }) => (
  <div>
    <p>`${name}`</p>
  </div>
)

will be mocked like

import React from 'react'
export const HelloComponent = (props) =>
  React.createElement('HelloComponent', props)