How to test 'describe' in tests with Jasmine (spec)?

Hellow, guys.

I’m trying to finish the spec of component in my project, and I’m having the trouble with ‘describe’ in my spec file.

The test is crashing in this line:

ngOnInit() {
//error here 'subscribe is not a function'
    this.appComponent.currentToken.subscribe(tokenRecebido => this.tokenRecebidoTemp = tokenRecebido);
  • Some observations:
  • The ‘appComponent’ above is mocked with ‘spyOn’ of jasmine:
let appComponentMock: any = {
    currentToken: tokenMock
beforeEach(() => {
    fixture = TestBed.createComponent(ListMenuSheetComponent);
    component = fixture.componentInstance;
    component.appComponent = appComponentMock;
    //and.returnValue({ subscribe: () => {} });

    //component.currentToken = new TokenEleicao();

But when the spec run, I’m getting the error ‘subscribe is not a function’…
Please, help.

You probably want to check what the type of component.appComponent.currentToken is during your beforeEach if it doesn’t have a subscribe, it’s probably not initialized as an observable yet.

I’ll try it. Thank so much. \o/

Good luck and happy coding.