Answers for "angular jasmine mock http request"

1

angular jasmine mock http request

// Angular - Jasmine
// Fake a HTTP request

public getSomething() : Observable<any>{
    let response: DataResult<any> = { data: "something" };
    return of(response);
}
Posted by: Guest on August-19-2021
1

angular jasmin mock http response

public static mockGetProfile(){
    const response = JSON.parse(`
     "name": "abc",
     "active": true,
     ...all other json fields that you want
     `);

    let obs = new Observable((subscriber) => {
        setTimeout(()=>{
            subscriber.next(response);
            subscriber.complete();
        }, 3000);
    });
    return obs;
}
Posted by: Guest on August-19-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language