Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help/document unit testing components that use teleport #26

Open
shirblc opened this issue Oct 6, 2024 · 0 comments
Open

Help/document unit testing components that use teleport #26

shirblc opened this issue Oct 6, 2024 · 0 comments

Comments

@shirblc
Copy link

shirblc commented Oct 6, 2024

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

Current behavior

I'm having trouble figuring out how to unit test teleported elements.

I'm using the teleport directive, which works perfectly in the build, but I'm having trouble figuring out how to unit test it. The example in the repo includes both the teleported content and the teleport outlet in the same component, which seems to work for this repo's tests, but my use case is slightly different - the outlet and content are in different components. I've tried adding a mock target component that has a teleport in it, similar to the teleport's unit test, but it doesn't seem to actually render the teleported content. Which means I can't test the DOM.

I think this is mostly a documentation issue - I'm sure there's a way to test it and I'm sure it'd be really useful to have directions for that written down somewhere. I'd be happy to write it down neatly in docs if I manage to make it work, too.

Expected behavior

Teleport should still work when unit testing. The teleport should teleport the elements to the mock container.

Minimal reproduction of the problem with instructions

https://github.com/shirblc/teleport-repro

What is the motivation / use case for changing the behavior?

I want to add unit tests for components that use teleport.

Environment


Angular version: 18.2.6-18.2.7


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v20.16.0
- Platform: Mac/Linux

Others:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant