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

Weird property access errors in angular templates #29

Open
hmil opened this issue Feb 4, 2021 · 2 comments
Open

Weird property access errors in angular templates #29

hmil opened this issue Feb 4, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@hmil
Copy link
Owner

hmil commented Feb 4, 2021

The following has been observed when omnimock mocks are passed as arguments to Angular template bindings:

Error: Failed: Unexpected property access: <UiKitTimeRangeSelectorApiService>.__zone_symbol__OriginalDelegate

The root cause is unknown. As a workaround, pass an empty backing object to the mock factory:

const myMock = mock<MyType>('myMock'); // Error
const myMock = mock<MyType>('myMock', {}); // No error

const myObject = mockInstance<MyType>('myObject'); // Error
const myObject = mockInstance<MyType>('myObject', {}); // No error
@hmil hmil added the bug Something isn't working label Feb 4, 2021
@iammvaibhav
Copy link

After the workaround, now I'm getting: Failed: Unexpected property access: <ngForm>.outerHTML

@hmil
Copy link
Owner Author

hmil commented Mar 13, 2021

For the record, here is what we found:

ngForm is not mocked by shallow-render. If your <input> components are wrapped by custom components, then those custom components are mocked and ngForm thinks that the form is empty, because it cannot see any actual <input> component.
This makes it pretty tricky to mock forms. Maybe one good way around this could be to tell shallow-render not to mock your low-level input components...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants