Skip to content

Add Test for CSS Modules #193

Closed
Closed
@justin808

Description

@justin808

See: https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client%2Fapp%2Fbundles%2Fcomments%2Fcomponents%2FCommentBox%2FCommentList%2FComment%2FComment.spec.jsx#L17

import { React, expect, TestUtils } from 'libs/testHelper';

import Comment from './Comment';

const {
  renderIntoDocument,
  findRenderedDOMComponentWithClass,
  findRenderedDOMComponentWithTag,
} = TestUtils;

describe('Comment', () => {
  it('renders an author and comment with proper css classes', () => {
    const component = renderIntoDocument(
      <Comment author="Frank" text="Hi!"/>
    );

    // TODO: Setup testing of CSS Modules classNames
    // const comment = findRenderedDOMComponentWithTag(component, 'div');
    // expect(comment.className).to.equal('comment');
    // const author = findRenderedDOMComponentWithTag(component, 'h2');
    // expect(author.className).to.equal('comment-author');
    const text = findRenderedDOMComponentWithTag(component, 'span');
    expect(text.className).to.equal('js-comment-text');
  });

  it('shows the author', () => {
    const component = renderIntoDocument(
      <Comment author="Frank" text="Hi!"/>
    );

    const author = findRenderedDOMComponentWithClass(component, 'js-comment-author');
    expect(author.textContent).to.equal('Frank');
  });

  it('shows the comment text in markdown', () => {
    const component = renderIntoDocument(
      <Comment author="Frank" text="Hi!"/>
    );

    const comment = findRenderedDOMComponentWithClass(component, 'js-comment-text');
    expect(comment.textContent).to.equal('Hi!\n');
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions