incalculable-caravan-20607
01/30/2023, 9:34 PMgreat-oil-15113
01/30/2023, 10:16 PMbreezy-plastic-64948
01/30/2023, 10:41 PMuseHistory
hook of react-router-dom
which is being imported and used by the component I am testing.
This is what i am trying to do without success:
import * as RRDom from 'react-router-dom';
describe('My test', () => {
it.only('test', () => {
cy.stub(RRDom, 'useHistory').returns({
push: () => {
console.log('push stubbed!');
},
});
cy.mount(<MyComp />);
cy.contains('Click me').click();
});
})
And here the simple Component
import { useHistory } from 'react-router-dom';
const MyComp = () => {
const history = useHistory();
return (
<div onClick={() => history.push('/somewhere')}>
Click me
</div>
}
This code throw an error when running the test: ES Modules cannot be stubbed
.
We are currently using Vite.
I don't want to touch the existing Component implementation by changing imports or whatsoever.
We have choosen Cypress Component Testing instead of React Testing Library but this limitation that seems unsolvable is a main concern, please let me knowstraight-pencil-91170
01/31/2023, 8:20 AMbillowy-pharmacist-61146
01/31/2023, 10:02 AM*.cy.ts
with @cypress/code-coverage
and Istanbul
.
The problem is that I can't exclude the *.cy.ts
files from coverage report.
Here is my configuration :
package.json :
"devDependencies": {
...
"@cypress/code-coverage": "3.10.0",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"cypress": "12.4.1",
"vite-plugin-istanbul": "4.0.0",
...
},
cypress.config.ts :
import { defineConfig } from 'cypress'
import registerCodeCoverageTasks from '@cypress/code-coverage/task'
export default defineConfig({
env: {
codeCoverage: {
exclude: ['cypress/**/*.*', 'src/**/*.cy.ts'],
},
},
component: {
devServer: {
framework: 'vue',
bundler: 'vite',
},
setupNodeEvents(on, config) {
registerCodeCoverageTasks(on, config)
return config
},
},
})
.nycrc.json :
{
"all": true,
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"include": [
"src/**/*.ts",
"src/**/*.vue"
],
"exclude": [
"src/**/*.cy.ts",
"cypress/**/*.*",
"**/*.d.ts",
"**/*.cy.ts"
],
"report-dir": "./coverage-cypress"
}
Anything I'm missing ?
Thanks for your help !future-piano-88787
01/31/2023, 11:34 AMgRPC services
for API and Cypress
for e2e testing, and looks like Cypress doesn't have a way or plugin to testing this.
Do we have some tricks or another way to testing gRPC APIs with Cypress.
thanks.orange-alarm-20012
01/31/2023, 3:07 PMstocky-insurance-27750
01/31/2023, 3:58 PMelement.trigger('click')
but it was a mistake. We're using storybook to display the page. I'm using the 'full screen' mode so it's not iframe related.
Very simple test
cy.get('element').click()
cy.url().should('include', '/stores')
I've tried using .wait(5000).click()
- focus().click()
- click({force:true})
and variations with `trigger('click')`too
If I use the cypress ui - the test closes as soon as the click event is finished, it won't wait or anything, so I can't debug it.
If I use the CLI in any way, the test hangs on the click()
and doesn't do anything. If I use the trigger('click')
the test runs but fails because the url doesn't change. Which makes me think the click isn't working there, either.
Any ideas anyone? I've been trying this for a few hours now.thousands-house-85089
01/31/2023, 4:17 PMjs
import { faker } from '@faker-js/faker';
Is it possible to import this globally without needing to put it on every spec file?
I've tried adding it to the e2e.js but it doesn't seem to work.
Thanksaloof-airport-25580
01/31/2023, 5:25 PMfresh-sandwich-8289
01/31/2023, 5:42 PM[
{
"name": "Should get 2 actions",
"type": "case",
"test_config": {
"method": "GET",
"endpoint": "/actions",
"query_parameters": {
"limit": 2
}
},
"expected": {
"status_code": 200
}
},
...
]
Then, a fixture called cases.json specifies which fixtures are needed to run:
["actions", "users", etc]
All of this is to allow teams to only write fixtures for their endpoints, and our CI process compiles the required parts and executes the desired test cases.
I'm struggling to find a proper strategy to load the fixtures.
Using the cy.fixture command ties me to run it inside an it() block and that is complicating things and leading me to nasty let
workarounds...
Do you have any suggestion? Should I load the json files from the FS using cy.task?
Thanks in advanceacceptable-fall-11897
01/31/2023, 6:36 PMsilly-student-97216
01/31/2023, 9:18 PMfaint-xylophone-59151
01/31/2023, 9:23 PMpowerful-answer-5604
01/31/2023, 10:09 PMsquare-ability-8372
01/31/2023, 11:22 PMabundant-rose-56989
02/01/2023, 9:36 AMbusy-flower-19102
02/01/2023, 10:40 AMbest-window-49967
02/01/2023, 10:50 AMbrash-plumber-67474
02/01/2023, 12:26 PMshould open app in new tab
, () => {
cy.mount();
cy.spy(window, 'open').as('windowOpen');
const uniqueAppName = 'Sample App';
const expectedURL = 'http://localhost/sampleapp';
cy.contains(uniqueAppName).should('be.visible').click();
cy.get('@windowOpen').should('have.been.calledWith', expectedURL, '_blank');
});
});
But the problem is the URL that opens up in new tab return 404 error and I know that it will return 404 because it is a dummy URL. I don't care whatever that new tab returns I just wanted to test if that URL was called by window.open function. While running the test in Cypress desktop app (using cypress open command)
the test shows it passed and runs all the other tests as well.
But when running the test using cypress run
command (in headless mode), the CLI passes the current test then throws error 404 and exits out and does not run rest of the tests. Is there a way to just ignore that error because I am anyway expecting it?
I have attached the error message.
If you think this is an incorrect approach to test a link in new tab, please do suggest what should be the right approach?
Another query:
If I am expecting an error that is known, like in above scenario I knew I will be getting a 404 error, is it a good practice to do error handling in a test environment like using try-catch blocks?bitter-agent-2072
02/01/2023, 6:13 PMfamous-table-6116
02/01/2023, 7:11 PMwide-book-80078
02/02/2023, 2:47 AMbillowy-pharmacist-61146
02/02/2023, 10:56 AMcypress/vue
, is there a way to mount a component and deal with v-model ?able-thailand-97732
02/02/2023, 11:00 AMbored-bear-79292
02/02/2023, 11:31 AMcurved-air-49341
02/02/2023, 12:18 PMcold-author-79999
02/02/2023, 12:49 PMbrash-tiger-52405
02/02/2023, 1:28 PMechoing-tent-95037
02/02/2023, 5:17 PM