dazzling-appointment-39028
08/09/2021, 1:48 PMthousands-gold-77695
08/09/2021, 1:50 PMthousands-gold-77695
08/09/2021, 1:50 PMdazzling-appointment-39028
08/09/2021, 2:18 PMdazzling-appointment-39028
08/09/2021, 2:18 PMthousands-gold-77695
08/09/2021, 2:19 PMthousands-gold-77695
08/09/2021, 2:19 PMcypress.json
you'll want to have this:
json
{
"component": {
"componentFolder": "src",
"supportFile": "cypress/support/support.tsx",
"testFiles": "**/*.spec.{js,ts,jsx,tsx}"
}
}
thousands-gold-77695
08/09/2021, 2:21 PMthousands-gold-77695
08/09/2021, 2:21 PMsupport.tsx
ts
/// <reference types="cypress" />
import { ChakraProvider, Box } from '@chakra-ui/react'
import { mount } from '@cypress/react'
import customTheme from '@theme/customTheme'
import { Fonts } from '@theme/Fonts'
import { createElement, ReactElement, ReactNode } from 'react'
const ThemeProvider = ({ children }: { children: ReactNode }): ReactElement => {
return (
<ChakraProvider resetCSS={true} theme={customTheme}>
<Fonts />
<Box my={4} mx={6}>
{children}
</Box>
</ChakraProvider>
)
}
Cypress.Commands.add('mount', (component) => {
mount(createElement(ThemeProvider, null, component))
})
Cypress.Commands.add('dataCy', (value) => {
return cy.get(`[data-cy=${value}]`)
})
thousands-gold-77695
08/09/2021, 2:22 PMpackage.json
you can simply add a script "cypress:tc": "cypress open-ct"
dazzling-appointment-39028
08/09/2021, 2:23 PMthousands-gold-77695
08/09/2021, 2:23 PMthousands-gold-77695
08/09/2021, 2:24 PMcypress open
it will open your end to end teststhousands-gold-77695
08/09/2021, 2:24 PMcypress open-ct
itll will open your component testsdazzling-appointment-39028
08/09/2021, 2:26 PMdazzling-appointment-39028
08/09/2021, 2:26 PMthousands-gold-77695
08/09/2021, 2:26 PMthousands-gold-77695
08/09/2021, 2:27 PMts
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.ts can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
const injectNextDevServer = require('@cypress/react/plugins/next')
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
require('@cypress/code-coverage/task')(on, config)
if (config.testingType === 'component') {
injectNextDevServer(on, config)
}
return config
}
thousands-gold-77695
08/09/2021, 2:27 PMthousands-gold-77695
08/09/2021, 2:28 PMrequire('@cypress/code-coverage/task')(on, config)
dazzling-appointment-39028
08/09/2021, 2:47 PMdazzling-appointment-39028
08/09/2021, 2:50 PMthousands-gold-77695
08/09/2021, 2:51 PMdazzling-appointment-39028
08/09/2021, 2:52 PMdazzling-appointment-39028
08/09/2021, 2:52 PMthousands-gold-77695
08/09/2021, 2:52 PMthousands-gold-77695
08/09/2021, 2:52 PMthousands-gold-77695
08/11/2021, 12:51 PM