After making updates to an Angular component, I encountered issues with broken unit tests. All test specs are failing, leading me to believe that the problem lies in the initialization within the beforeEach
calls. Despite extensive research, I have been unable to resolve the issue.
The error message I receive when running my unit tests is:
TypeError: Cannot read property 'subscribe' of undefined
The only instances where subscribe
is called are:
this.ruleDataFieldOption$.subscribe
...
this.submitted$.subscribe
...
this.dataFieldControl.valueChanges.subscribe
I attempted to explicitly initialize ruleDataFieldOption$
by setting it to of(mockRuleDataFields)
, but this did not solve the problem. Additionally, moving the code block from the second beforeEach
call into the promise of the async beforeEach
call (i.e.
.compileComponents().then( () => {...} )
) also proved unsuccessful.
client-rules-condition.component.spec.ts
// Test setup code goes here
.
.
.
it('should create', () => {
// Test expectations go here
});
client-rules-condition.component.ts
@Component({
selector: 'nd-client-rules-condition',
templateUrl: './client-rules-condition.component.html',
styleUrls: ['./client-rules-condition.component.scss']
})
export class ClientRulesConditionComponent implements OnInit {
// Component logic goes here
}
It appears to be a minor issue, and I am determined to make my unit tests pass successfully.