DEV Community

Testing a Semantic UI React Input with React Testing Library

jacobwicks on December 04, 2019

I'm working on a React project using Semantic UI React. I'm doing unit testing with Jest and React Testing Library (RTL). A common situation when ...
Collapse
 
instinct profile image
Instinct

Nice Article!

I have like many imports from 'semantic-ui-react'.

import { Modal, ModalHeader, ModalContent, ModalActions, Button } from 'semantic-ui-react';
Enter fullscreen mode Exit fullscreen mode

Do I have to write functions for all of them?
Is there an easier way to do this?

Collapse
 
paukman profile image
ALEKSANDAR TRKULJA • Edited

Hey Jacob, nice explanation. I'm struggling to do the same with semantic ui dropdown, but can't find anything. Do you perhaps have anything on that one? Thanks.

Collapse
 
jacobwicks profile image
jacobwicks

Sure. I didn't take screenshots, but I did a writeup of it on my github pages blog here:
jacobwicks.github.io/2020/05/16/te...

Hope that helps.

Collapse
 
paukman profile image
ALEKSANDAR TRKULJA

It worked, thanks a lot.

Collapse
 
instinct profile image
Instinct

Okay, I did that the following way:

jest.mock("semantic-ui-react", () => {
    const ui = jest.requireActual("semantic-ui-react");
    return { ...ui };
})
Enter fullscreen mode Exit fullscreen mode