Jasmine angular testing async promise

Discussão em 'Angular' iniciado por beanic, Outubro 28, 2024.

  1. beanic

    beanic Guest

    I need test an asyncronus promise in Jasmin and I don't know how to do it becase angular return an error every time.

    myService.ts

    async getNewContext(): Promise<IContext> {
    const test1 = await this.service1.function();
    const test2 = await this.service2.function();
    const test3 = await this.service3.function();
    const test4 = await this.service4.function();

    const cc = {
    .
    .
    .
    };

    this.setContext = cc;

    return cc;
    }


    component.ts

    setFeatures() {
    this.myService.getNewContext().then((response) => {});
    }


    component.spect.ts

    .
    .
    .
    beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
    declarations: [...],
    imports: [...],
    providers: [
    {
    provide: myService,
    useValue: {
    select: () => [],
    getNewContext: () => [],
    },
    }
    ],
    }).compileComponents();
    }));


    I am getting an error saying "getNewContext is not a function". Any idea please?

    Continue reading...

Compartilhe esta Página