https://cypress.io logo
Component testing vs Jest
# i-need-help
p
My client wants to use Component testing over Jest for unknown to me reason. Is there is any advantages/disadvantages comparison? Or why someone would switch to Cypress Components over Jest.
f
You don't get an actual browser with Jest. Usually people go with Jest because its familiar to them. You can totally use it if that's what you're used to, but you're going to be missing out on 60%+ of what you could be testing with HTML/CSS/User behaviors.
p
@few-farmer-48800 Project is build on Angular and I do only integration/e2e tests for it. It's outsourcing job so I cant get good understanding of what's the other site point of view. They don't have any unit tests right now, and a lot of developers starting to work with cypress, so probably they think it would be advantageous to use same tool for all kinds of tests instead additionally Jest.
But i didnt realise you could also tests html/css attributes with cypress and couldnt with Jest.
f
You don't get a test harness when you test with Jest, that's its downfall
p
Im just trying to prepare for them little pros/cons for Jest vs Cypress
w
Main advantage of jest would be execution speed - no browser means fast execution. But also lower confidence as bugs that only show up in a browser rendering engine will never happen in a node test, so can’t be caught. I’d argue having a consistent DX between e2e and component tests is worth a ton - no context switching, same commands, even shared custom commands all works great. You even get videos and screenshot assets from CI, because it really rendered. And finally debugging and building in a real browser removes a whole category of pain and workarounds related to fighting jsdom, missing browser APIs, and debugging HTML in the terminal trying to imagine how the component might have looked during the test. I have post about it on the Cypress blog: https://www.cypress.io/blog/2022/12/15/cypress-component-testing-for-developers/ And you can find more if you check out the Component Testing tag there. There’s probably one other win for jest besides execution speed, which is shallow mounting. It doesn’t make much sense to shallow mount in the browser. Users will never interact with a shallow mounted component. But sometimes people are used to doing it and it’s an adjustment.