@codeshift/test-utils

Accepts a transform and a code string and runs the transform against it.

Usage no npm install needed!

<script type="module">
  import codeshiftTestUtils from 'https://cdn.skypack.dev/@codeshift/test-utils';
</script>

README

@codeshift/test-utils

applyTransform

Accepts a transform and a code string and runs the transform against it.

Works well with Jest's toMatchInlineSnapshot and toMatchSnapshot assetions.

Example:

it('should wrap avatar in a tooltip', () => {
  const result = applyTransform(
    transformer,
    `
      import Avatar from '@atlaskit/avatar';

      const App = () => {
        return <Avatar name="foo" />;
      }
    `,
    { parser: 'tsx' },
  );

  expect(result).toMatchInlineSnapshot(`
    "import Tooltip from '@atlaskit/tooltip';
      import Avatar from '@atlaskit/avatar';

      const App = () => {
        return <Tooltip content=\\"foo\\"><Avatar name=\\"foo\\" /></Tooltip>;
      }"
  `);
});