Stryker

ajax.js - Stryker report

File / Directory
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Runtime errors
# Transpile errors
Total detected
Total undetected
Total mutants
ajax.js
65.96 %
65.96 31 16 0 0 0 0 31 16 47
Expand all
/**
 * Sending request
 * @param {Object} options - Sending options
 * @param {string} options.url
 * @param {string} options.enctype - Sending options
 * @param {string} options.sendType - Sending options
 * @param {string} options.method - Sending options
 * @param {string|FormData} options.data - Sending options
 * @param {function} translate
 * @param {function} RequestType
 * @returns {Promise}
 * todo rewrite to fetch
 */
export function ajax(options, translate, RequestType = XMLHttpRequest) 0{
    return new Promise((resolve, reject) => 1{
        const xhr = new RequestType();

        const url = 2options.url + (345678options.method.toUpperCase() === 9'GET' && options.data ? 10`?${options.data}` : 11'');

        xhr.open(options.method, url, 12true);

        if (131415options.sendType === 16'serialize') 17{
            xhr.setRequestHeader(18'Content-type', options.enctype);
        } else if (192021options.sendType === 22'json') 23{
            xhr.setRequestHeader(24'Content-type', 25'application/json; charset=utf-8');
        }

        xhr.onreadystatechange = () => 26{
            if (272829xhr.readyState === 4) 30{
                if (313233xhr.status === 200) 34{
                    let response = {};

                    try 35{
                        response = JSON.parse(xhr.responseText);
                    } catch (e) 36{
                        response.validationErrors = 37{
                            base: 38[translate(39'JSON parsing error')],
                        };
                    }

                    resolve(response);
                } else 40{
                    reject(41{
                        xhr,
                        method: options.method,
                        url: options.url,
                        status: xhr.status,
                        statusText: xhr.statusText,
                    });
                }
            }
        };

        xhr.send(424344options.method.toUpperCase() === 45'POST' ? options.data : 46'');
    });
}

export default ajax;
# Mutator State Location Original Replacement
0 Block Killed 13 : 71 { ...}); } {}
1 Block Killed 14 : 44 { ... } {}
2 BinaryExpression Killed 17 : 20 . ...: '') . ...: '')
3 BinaryExpression Killed 17 : 35 . ... . . ... .
4 ConditionalExpression Killed 17 : 35 . ... .
5 ConditionalExpression Killed 17 : 35 . ... .
6 BinaryExpression Killed 17 : 35 . ...' ' . ...' '
7 ConditionalExpression Killed 17 : 35 . ...' '
8 ConditionalExpression Killed 17 : 35 . ...' '
9 StringLiteral Killed 17 : 68 ' ' ""
10 StringLiteral Killed 17 : 92 `?${ ... }` ""
11 StringLiteral Killed 17 : 113 '' " ... !"
12 BooleanSubstitution Killed 19 : 38
13 IfStatement Killed 21 : 12 . ... '
14 IfStatement Killed 21 : 12 . ... '
15 BinaryExpression Killed 21 : 12 . ... ' . ... '
16 StringLiteral Killed 21 : 33 ' ' ""
17 Block Killed 21 : 46 { ... } {}
18 StringLiteral Killed 22 : 33 ' - ' ""
19 IfStatement Killed 23 : 19 . ... '
20 IfStatement Killed 23 : 19 . ... '
21 BinaryExpression Killed 23 : 19 . ... ' . ... '
22 StringLiteral Killed 23 : 40 ' ' ""
23 Block Killed 23 : 48 { ... } {}
24 StringLiteral Killed 24 : 33 ' - ' ""
25 StringLiteral Killed 24 : 49 ' ... - ' ""
26 Block Survived 27 : 39 { ... } {}
27 IfStatement Survived 28 : 16 . ===
28 IfStatement Survived 28 : 16 . ===
29 BinaryExpression Survived 28 : 16 . === . !==
30 Block Survived 28 : 38 { ... } {}
31 IfStatement Survived 29 : 20 . ===
32 IfStatement Survived 29 : 20 . ===
33 BinaryExpression Survived 29 : 20 . === . !==
34 Block Survived 29 : 40 { ... } {}
35 Block Survived 32 : 24 { ... } {}
36 Block Survived 34 : 32 { ... } {}
37 ObjectLiteral Survived 35 : 52 { ... } {}
38 ArrayLiteral Survived 36 : 34 [ ... ')] []
39 StringLiteral Survived 36 : 45 ' ... ' ""
40 Block Survived 41 : 23 { ... } {}
41 ObjectLiteral Survived 42 : 27 { ... } {}
42 BinaryExpression Killed 53 : 17 . ... ' . ... '
43 ConditionalExpression Killed 53 : 17 . ... '
44 ConditionalExpression Killed 53 : 17 . ... '
45 StringLiteral Killed 53 : 50 ' ' ""
46 StringLiteral Killed 53 : 74 '' " ... !"