ng-mocks icon indicating copy to clipboard operation
ng-mocks copied to clipboard

Bug: Erroneous test setup due to the usage of contentChildren

Open LukasMachetanz opened this issue 9 months ago • 7 comments

Description of the bug

Let's assume having a component SystemUnderTestComponent as the SUT. This component internally renders ActionsComponent, which will be mocked within the test setup. ActionsComponent uses the new API contentChildren for accessing its content children. Unfortunately this API causes problems for SystemUnderTestComponent as the following error is thrown: TypeError: Cannot read properties of undefined (reading 'Symbol(SIGNAL)').

An example of the bug

https://codesandbox.io/p/sandbox/competent-fermat-llrjgt?file=%2Fsrc%2Ftest.spec.ts%3A35%2C35

Expected behavior

I would expect that the tests of SystemUnderTestComponent are not influenced by internals of the mocked component ActionsComponent.

Maybe this behavior is caused by the fact that ActionsComponent is mocked and Angular can't find ActionComponent?

LukasMachetanz avatar May 06 '24 09:05 LukasMachetanz

Possibly duplicate of https://github.com/help-me-mom/ng-mocks/issues/8634

andreandersson avatar May 06 '24 12:05 andreandersson

@andreandersson, definitely. I experienced the same problem with viewChild as well.

LukasMachetanz avatar May 06 '24 12:05 LukasMachetanz

Any news on this issue? This bug really prevents using the new API.

LukasMachetanz avatar Jun 04 '24 14:06 LukasMachetanz

Same here. It seems that @ContentChildren(...) still works fine, but contentChildren(...) throws mentioned exception

@satanTime Any idea?

PieterjanDeClippel avatar Jul 07 '24 11:07 PieterjanDeClippel

@PieterjanDeClippel has created a minimal repro here: https://github.com/PieterjanDeClippel/signaltesting/tree/master/src/app As mentioned by others, the issue arises when we use for example: MockDirective(BsCheckboxGroupDirective) and the BsCheckboxGroupDirective is using the new signal based queries.

wall-street-dev avatar Jul 11 '24 14:07 wall-street-dev

Any news on this issue?

squelix avatar Jul 16 '24 07:07 squelix

Any news on this issue?

A workaround in the meantime... 😕 https://stackoverflow.com/a/78736480/1277159

wall-street-dev avatar Jul 16 '24 08:07 wall-street-dev