NCIOCPL / ncids

NCI Design System
7 stars 5 forks source link

Add Tests for Frontmatter Markdown and Utility Table Factory #1713

Open dlescarbeau opened 1 month ago

dlescarbeau commented 1 month ago

Create tests that satisfy our code coverage metrics for the new utility page template functionality, specifically the files within /utility-page-layout/. This would include files for utility-class-table-factory as well as frontmatter-markdown.

Parent Issue: #1593

Notes

dlescarbeau commented 1 month ago

The original test JS that was failing for frontmatter-markdown

import { render, screen } from '@testing-library/react';
import React from 'react';

import FrontmatterMarkdown from '../frontmatter-markdown';

describe('Utility Class Table Factory', () => {
    it('renders the contents', async () => {
        const markdown = `
            ## Some h2
        `;
        render(<FrontmatterMarkdown content={markdown} />);
        expect(screen.getByRole('heading', {
            level: 2,
        })).toHaveTextContent('Some h2');
    });
    it('renders nothing with empty content', async () => {
        const { container } = render(<FrontmatterMarkdown content={markdown} />);
        expect(container).toBeEmptyDOMElement();
    });

});
dlescarbeau commented 1 month ago

The error text:

 FAIL  src/components/__tests__/frontmatter-markdown.test.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/derlesca/Development/ncids/node_modules/.pnpm/react-markdown@8.0.7_@types+react@18.2.53_react@17.0.2/node_modules/react-markdown/index.js:6
    export {uriTransformer} from './lib/uri-transformer.js'
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      2 | import PropTypes from 'prop-types';
      3 |
    > 4 | import ReactMarkdown from 'react-markdown';
        | ^
      5 | import remarkGfm from 'remark-gfm';
      6 | import rehypeRaw from 'rehype-raw';
      7 | import { withPrefix } from 'gatsby-link';

      at Runtime.createScriptFromCode (../node_modules/.pnpm/jest-runtime@29.7.0/node_modules/jest-runtime/build/index.js:1505:14)
      at Object.require (src/components/frontmatter-markdown.jsx:4:1)
      at Object.require (src/components/__tests__/frontmatter-markdown.test.js:4:1)