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

Tried to bind to a property that is not marked as @Input: vm from base class #217

Closed
rodrigofante opened this issue Apr 20, 2022 · 13 comments · Fixed by #234
Closed

Tried to bind to a property that is not marked as @Input: vm from base class #217

rodrigofante opened this issue Apr 20, 2022 · 13 comments · Fixed by #234

Comments

@rodrigofante
Copy link

rodrigofante commented Apr 20, 2022

I have an abstract base class that includes an @input property, when I extend that base class I use that input in many places in the extended class.

The issue I'm having is that, when testing it on binding that property I get the following error:
Error: Tried to bind to a property that is not marked as @Input: vm

Here's an example on what would be the scenario:

export abstract class BaseClass{
   @Input() public vm: MyProperty;
}

export class MyComponent extends BaseClass{
  //code here
}

now, if I try to initialise my test in the following way:

beforeEach(async () => {
  shallow = new Shallow(MyComponent, MyModule);
  const { instance } = await shallow.declare().render({ bind: { vm: myMockValue } });
});

this will break when I run it as it won't identify the vm property as an input, which is, but it's declared in the base class, not in the child class (the one I'm testing).

Is this a bug or am I supposed to test in a different way when the @input is declared in the base class?

@Ishou
Copy link

Ishou commented May 23, 2022

I can confirm this is a bug that appeared with the Angular 13 compatibility update, the same code was working correctly before.

@Ishou
Copy link

Ishou commented May 25, 2022

Here is a workaround I just found:

export class MyComponent extends BaseClass {
  @Input() public override vm: MyProperty;
}

@antch
Copy link

antch commented Aug 4, 2022

Also running into this -- thank you for the workaround but it unfortunately adds a ton of boilerplate. In the case of overriding a setter it gets especially verbose. Hopefully this is just a regression that can be resolved...

@getsaf
Copy link
Owner

getsaf commented Aug 7, 2022

Sorry for the delays, I cannot reproduce this issue, see #220.

Could you provide a reproduction?

@antch
Copy link

antch commented Aug 8, 2022

I was able to get your test to fail by adding either an @Input or @Output to the sub-class, for example:

@Component({
    'selector': 'my-component'
})
class MyComponent extends BaseClass {
    @Input() label = 'foo';
}

Error:

Error: Tried to bind to a property that is not marked as @Input: enabled
Available input bindings: label

@getsaf getsaf closed this as completed Aug 8, 2022
@antch
Copy link

antch commented Aug 8, 2022

I'm wondering as to why this was closed, it seems like a valid issue?

@getsaf getsaf reopened this Aug 8, 2022
@getsaf
Copy link
Owner

getsaf commented Aug 8, 2022

Sorry about that, was unintentional. I can try looking into this later today.

@JoeBeer
Copy link

JoeBeer commented Oct 5, 2022

@getsaf What is the status of this issue?

@johnwest80
Copy link

@getsaf hey there, me again. looks like we're hitting this one, too. can't do much, but i'll owe you a cup of coffee for helping with these issues :). thx.

@getsaf
Copy link
Owner

getsaf commented Dec 20, 2022

Hey @johnwest80 hope all is well. The I/O detection I had in place was not taking inheritance into account properly. Should be fixed in v14.2.1.

Again, sorry for the delays on this, I don't get to do much Angular work lately. I do plan on updating this to NG 15 soon too unless someone in the community wants to give it a go.

@antch
Copy link

antch commented Dec 20, 2022

Thank you for addressing this -- is there any hope of the fix being back-ported into 13.x as that's where it started occurring?

@getsaf
Copy link
Owner

getsaf commented Dec 21, 2022

I will have some time off for the holidays soon. I think it'll be easy to backport.

@getsaf
Copy link
Owner

getsaf commented Dec 23, 2022

@antch I just backported this to 13.0.2!

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

Successfully merging a pull request may close this issue.

6 participants