The Cypress docs have a typo, you should import this
import 'tailwindcss/dist/tailwind.min.css'
not this
import 'tailwindcss/dist/tailwindcss.min.css' // causes error, not in node_modules
import React from 'react';
import { mount } from '@cypress/react';
import App from './App';
import './index.css';
import 'tailwindcss/dist/tailwind.min.css'
it('should renders the App correctly', () => {
mount(<App />)
cy.get('h1').contains('Cypress Component Testing with Tailwind CSS')
.should('have.css', 'font-family')
.and('match', /Georgia/) // passes
});
Or can use the cracao plugin in cypress/plugins/index.js
yarn add -D @cypress/react
//or
npm install -D @cypress/react
const cracoConfig = require('../../craco.config.js')
const injectDevServer = require('@cypress/react/plugins/craco')
module.exports = (on, config) => {
injectDevServer(on, config, cracoConfig)
return config
}
which activates the contents of craco.config.js
(you already have)
module.exports = {
style: {
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
}
import React from 'react';
import { mount } from '@cypress/react';
import App from './App';
import './index.css';
// import 'tailwindcss/dist/tailwind.min.css' // not required, plugin works
it('should renders the App correctly', () => {
mount(<App />)
cy.get('h1').contains('Cypress Component Testing with Tailwind CSS')
.should('have.css', 'font-family')
.and('match', /Georgia/) // passes
});