I am trying to test a simple function in angular using karma and jasmine.
class
export class Acl {
async caller() {
console.log("first statement");
const calledMe = await this.callMe().toPromise();
return calledMe;
}
callMe() {
return new Observable((observer) => observer.next({ something: "key" }));
}
}
test file
import { Acl } from "./main";
import { fakeAsync, tick } from "@angular/core/testing";
import { Observable } from "rxjs";
describe("Hello world", () => {
it("test the async", fakeAsync(() => {
const t = new Acl();
spyOn(t, "callMe").and.returnValue(
new Observable((observer) => observer.next({ something: "key" }))
);
const cl = t.caller();
console.log("a print ", cl);
tick();
}));
});
the output for the print statement in the test case is

How to test such functions.