The visual appearance of the Material UI modal varies between the server (CI) and local environments

I am encountering an issue with a Jest/React testing library snapshot that fails on the server, but locally the snapshot does not update even when using the --ci option.

The problem specifically involves a modal component from Material UI.

import {Modal} from '@mui/material';
(...)

<Modal
      open={isOpen}
      onClose={toggleModal}
      disableEscapeKeyDown
      hideBackdrop={false}> // also attempted to remove this prop, since default is false but makes no difference
      (...)
</Modal>

Snapshot Test:

it('should match snapshot', () => {
    renderComponent();
    expect(wrapper.baseElement).toMatchSnapshot();
  });

Here are the scripts in package.json used to run the tests:

(...)
"test": "jest",
"test:ci": "jest --ci",

Locally, the snapshot remains unchanged despite attempts to update it using the -u option:

(...)
class="MuiBackdrop-root css-i9fmh8-MuiBackdrop-root-MuiModal-backdrop"

However, on the server, the snapshot does get updated as expected when running "npm run test:ci":

(...)
-       class="MuiBackdrop-root css-i9fmh8-MuiBackdrop-root-MuiModal-backdrop"
+       class="MuiBackdrop-root MuiModal-backdrop css-i9fmh8-MuiBackdrop-root-MuiModal-backdrop"

The discrepancy lies in the introduction of 'MuiModal-backdrop' in the middle of the class name, which I cannot control since it is a hidden element generated by Material UI itself, as seen in the local snapshot:

<div
      aria-hidden="true"
      class="MuiBackdrop-root css-i9fmh8-MuiBackdrop-root-MuiModal-backdrop"
      style="opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;"
    />

I am using the same node version (v16.18.1) in both my local environment and CI setup. Any insights on what might be causing this issue?

Answer №1

To resolve the issue, the updated Material UI version was required, specifically: "@mui/material": "^5.11.2",

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to simultaneously wait for the completion of two methods instead of awaiting each one individually?

When dealing with 2 async methods, one may want to run them simultaneously but wait for both to finish before proceeding. Here is an example: exports.get = async id => { const part1 = await context.get(id); const part2 = await context.get2(id ...

Running the `npm run coverage` command results in an error message stating: "Function 'require(...).internalModuleStat' is not

We're encountering a strange issue while running our tests. When we use the command npm run test, everything seems to be passing without any problems. However, when we switch to npm run coverage, some of the tests fail with the following error message ...

Execute a personalized function while utilizing the routing table on a reverse proxy through node-http-proxy

After exploring the functionality of node-http-proxy, I've discovered a seamless way to route a sub-directory to various ports on a local server. However, an unresolved query lingers - is there a method to execute a customized function during the rout ...

How to choose between AWS.DynamoDB and AWS.DynamoDB.DocumentClient for your specific use case?

As I delve into learning DynamoDB and the AWS serverless stack, I've noticed that many tutorials recommend using AWS.DynamoDB.DocumentClient. This is exemplified by the following code snippet used to create an item: const dynamodb = new AWS.DynamoDB. ...

Testing React components with the React Testing Library and Material UI version 4, exploring hidden components

Exploring react testing library for the first time. I encountered an issue while attempting to test my code that is wrapped with the Hidden Component from material UI. Surprisingly, despite the component being visible in the DOM, the test fails. Snippet o ...

React hooks allow components to function properly even if the setState function is not explicitly called

Check out my React hooks code below: function State(){ var [msg,set_msg]=React.useState("hello") //not rendered, just to force render var [data,set_data]=React.useState({version:1}) function onClick(){ set_msg(x=>x+'x') //just to force ...

Passing an object from an Angular application to a backend server in Node.js using the

I have a YAML file with the following structure: Layouts: - Name: Default Layout LayoutId : 1 ConfiguredSegments: LiveA : Height : 100 Id : LiveA Ref1A : ...

It appears that React is rendering all elements, but only the first one is being shown

I am currently working on a component: const StudentName = (student) => ( <div key={student.engName} test={console.log("Name: "+student.val().engName)}> <Typography className={ student==currentStudent ? 's ...

Error: The data entered is invalid because the delimiter ":" [0x3a] is missing in nodejs

I seem to be encountering an issue: Error: The data is invalid and there seems to be a missing delimiter ":" [0x3a] at Function.decode.find (/Users/Seleena/Documents/torrent/node_modules/bencode/lib/decode.js:114:9) at Function.decode.buffer ...

The jade code is causing an error to be displayed

The following Jade code seems to be malfunctioning. head script(src='http://d3js.org/d3.v3.min.js') script(src='http://dimplejs.org/dist/dimple.v2.1.0.min.js') body script(type='text/javascript') var svg ...

Deliver an extensive JSON reply through a Node.js Express API

When dealing with a controller in a node/express API that generates large data sets for reports, reaching sizes as big as 20Mb per request, maintaining a positive user experience becomes essential. What strategies can be employed to efficiently handle suc ...

Why isn't changing the property of a Sequelize instance having any effect?

While I've successfully used the standard instance syntax in the past, I'm facing a challenge with updating an instance retrieved from the database in this specific section of my code. ... const userInstance = await db.models.Users.findOne({wher ...

Typescript's spellbinding courses

I'm encountering some issues with Typescript and the "@botstan/Magic" library in nodejs. Before we proceed, please take a look at the "Magic" documentation. Follow these lines: import Magic from "@botstan/magic"; import * as _ from "lodash"; @ ...

A simple guide on how to surround every incorrect input index in mapped inputs with red borders

I am incorporating a modal that corresponds each element of the object newCompanies to a specific row: {newCompanies.map((company, index) => { return ( <div> <div className="side- ...

Attempt to import Recharts into React was unsuccessful

I am currently exploring the use of recharts in a React project, but I am facing difficulties when trying to import components from its library. I have added it to my package.json file as follows: "recharts": "^2.0.9", However, I am ...

Using a third-party React component within a web-based forms application

Is it possible to include a Material UI component (https://material-ui.com/getting-started/usage/) in a web forms application? Below is the code I currently have, but it is not displaying the Button component. I am working with an ASPX file and using UMD ...

Personalize Badge Component

I've been on the hunt for a solution to customize a badge component similar to what's seen here: https://mui.com/material-ui/react-badge/. As of now, only options for making it a dot or adding a number in a circle are available. However, I' ...

"Can you explain the process by which React grabs the props using the code `const props = this.props

I recently came across an interesting article authored by Dan. The example provided in the article caught my attention: class ProfilePage extends React.Component { showMessage = (user) => { alert('Followed ' + user); }; handleClick ...

Prevent the opening of tabs in selenium using Node.js

Currently, I am using the selenium webdriver for node.js and loading an extension. The loading of the extension goes smoothly; however, when I run my project, it directs to the desired page but immediately the extension opens a new tab with a message (Than ...

What steps can I take to prompt a ZMQ Router to throw an error when it is occupied?

In my current setup, I have a configuration with REQ -> ROUTER -> [DEALER, DEALER... DEALER]. The REQ acts as a client, the ROUTER serves as a queue, and the DEALER sockets are workers processing data and sending it back to ROUTER for transmission to ...