admin管理员组

文章数量:1122832

Currently trying to write unit test for frontend. but I'm having issues with how the expected type. I keep getting expected 'Expected<HttpResponse>' on my provided mock response. I have my mock response set up like

        const resp = {
            body: null,
            status: 200,
            statusText: 'Success',
            type: HttpEventType.Response,
            clone: '',
            headers: '',
            url: '',
            ok: ''
        };

thanks!

Currently trying to write unit test for frontend. but I'm having issues with how the expected type. I keep getting expected 'Expected<HttpResponse>' on my provided mock response. I have my mock response set up like

        const resp = {
            body: null,
            status: 200,
            statusText: 'Success',
            type: HttpEventType.Response,
            clone: '',
            headers: '',
            url: '',
            ok: ''
        };

thanks!

Share Improve this question edited Nov 21, 2024 at 23:56 Naren Murali 54.6k5 gold badges40 silver badges70 bronze badges asked Nov 21, 2024 at 19:17 limiwinkslimiwinks 413 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The test cases sometimes throw error for full typing not being present, but we cannot waste time, providing the full typing for all test cases, the solution is to use any to override these typing errors and just test the values returned.

    const resp = {
        body: null,
        status: 200,
        statusText: 'Success',
        type: HttpEventType.Response,
        clone: '',
        headers: '',
        url: '',
        ok: ''
    } as any;

This as any will bypass the typescript error.

本文标签: angularjsAngular Unit Testing How to mock HttpResponse (JasminKarma)Stack Overflow