Relative Content

Tag Archive for angularjestjs

Variable initialized in constructor is null in ngOnInit only when testing

I am trying to test Angular components with jest. One component initializes an inherited (previously undefined) variable in its constructor. When running the application it works as expected. When I run my test and call MockRender(MyComponent), the variable is initialized in the constructor but when the ngOnInit-Block is reached, it is null (only for testing, not when running the application).

How to write the test case for the @input in jest

I am using Angular with Jest for unit testing, But now stuck with @Input Set method. I have tried in multiple ways but couldn’t able to get the solution.
For Example
@Input set global(val) { this.globalObj = val; }