Open dgrbrady opened 2 years ago
Update: I implemented unit tests in a different component in my ui lib, and it works just fine... so there's something funky about my TaskbarComponent
code... Feel free to close, but if anyone has any ideas, I'd love to get some extra eyes on it!
Update 2: I figured out what was causing the issue with TaskbarComponent
, but I have no idea why this is an issue. It was failing due to the order of the imports in the spec.ts
file.
So this would fail (also fails in any spec.ts
file):
import { TaskbarComponent } from './taskbar.component';
import { initEnv, mount } from 'cypress-angular-unit-test';
But THIS fixes it??
import { initEnv, mount } from 'cypress-angular-unit-test';
import { TaskbarComponent } from './taskbar.component';
For some reason, cypress-angular-unit-test
HAS to be imported before the component you're testing. Is this intended behavior? If so, it might be a useful thing to add to the README.
Current behavior
I have an Nx monorepo with 1 Angular app and 1 Angular lib (not buildable/publishable). I have successfully managed to implement
cypress-angular-unit-test
for the app, but when trying to implement in my lib, I get the following error when running a component unit testDesired behavior
Cypress Component testing should work inside an Nx library using the same setup that works for Nx application.
Test code to reproduce
I'm not exactly sure if this is a bug with the library because of the following:
spec.ts
file.Component test in my lib:
But if I do this instead,
It works fine? I'm at a loss here. There's not a whole lot of documentation out there for getting Cypress component testing working in an Nx workspace. Anyone else ever get this library working in an Nx workspace? Any guidance is super appreciated!
Also, here's the code for the WORKING unit tests in my Nx app
This is for my portfolio site, you can find the repo here. I'm using the command
npx cypress open-ct -C libs\ui\cypress.json
to run the Cypress runner for the ui lib, andnpx cypress open-ct -C apps\desktop\cypress.json
to run the Cypress runner for the app.Versions
Output from
npm ls
:package.json