Skip to content

ngOnChanges not called when setting properties #348

@dedwardstech

Description

@dedwardstech

I'm submitting a...


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

Current behavior

When setting properties via createComponentFactory(TestComponent)({ props: {} }), ngOnChanges is not called.

Expected behavior

In the Angular LifeCycle, ngOnChanges is called when properties are set initially and it's called before ngOnInit(). This is a known problem unit testing components that aren't inside a host component, because directly setting properties on a component bypasses change detection.

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

I think that inside setProps() a SimpleChanges object can be built and the ngOnChanges function can be fired. This would help avoid confusion and google searches on why ngOnChanges isn't firing initially when directly testing a component.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions