hmil / omnimock

Delicious mocks for TypeScript
Other
8 stars 1 forks source link

Weird property access errors in angular templates #29

Open hmil opened 3 years ago

hmil commented 3 years ago

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
iammvaibhav commented 3 years ago

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

hmil commented 3 years ago

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...