How to use the comb.deepEqual function in comb

To help you get started, we’ve selected a few comb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github doug-martin / super-request / index.js View on Github external
throw new Error("expected cookie " + key + " to be null or undefined " + "\n" + expect[2]);
                    }
                    break;
                case "header":
                    //it is a header test
                    var header = expect[1].toLowerCase();
                    val = expect[2];
                    if (header in headers) {
                        if (comb.isRexExp(val)) {
                            if (!val.test(headers[header])) {
                                throw new Error('Expected "' + expect[1] + '" matching ' + val + ', got "' + headers[header] + '"' + "\n" + expect[3]);
                            }
                        } else {
                            if (header === "location") {
                                var actual = headers[header];
                                if (!comb.deepEqual(actual, val)
                                    && !comb.deepEqual(actual, this._baseUrl + val)
                                    && !comb.deepEqual(actual, this._baseUrl.replace(/^http[s]?:/, "") + val)) {
                                    throw new Error([
                                        'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                    ].join("") + "\n" + expect[3]);
                                }
                            } else if (!comb.deepEqual(headers[header.toLowerCase()], val)) {
                                throw new Error([
                                    'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                ].join("") + "\n" + expect[3]);
                            }
                        }
                    } else {
                        throw new Error('Expected "' + expect[1] + '" header field' + "\n" + expect[3]);
                    }
                    break;
github doug-martin / super-request / index.js View on Github external
if (header in headers) {
                        if (comb.isRexExp(val)) {
                            if (!val.test(headers[header])) {
                                throw new Error('Expected "' + expect[1] + '" matching ' + val + ', got "' + headers[header] + '"' + "\n" + expect[3]);
                            }
                        } else {
                            if (header === "location") {
                                var actual = headers[header];
                                if (!comb.deepEqual(actual, val)
                                    && !comb.deepEqual(actual, this._baseUrl + val)
                                    && !comb.deepEqual(actual, this._baseUrl.replace(/^http[s]?:/, "") + val)) {
                                    throw new Error([
                                        'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                    ].join("") + "\n" + expect[3]);
                                }
                            } else if (!comb.deepEqual(headers[header.toLowerCase()], val)) {
                                throw new Error([
                                    'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                ].join("") + "\n" + expect[3]);
                            }
                        }
                    } else {
                        throw new Error('Expected "' + expect[1] + '" header field' + "\n" + expect[3]);
                    }
                    break;
                case "body":
                    val = expect[1];
                    if (comb.isHash(val)) {
                        //the body should be json
                        var json;
                        try {
                            json = comb.isString(body) ? JSON.parse(body.replace(/\\n/g, "")) : body;
github doug-martin / super-request / index.js View on Github external
}
                    break;
                case "header":
                    //it is a header test
                    var header = expect[1].toLowerCase();
                    val = expect[2];
                    if (header in headers) {
                        if (comb.isRexExp(val)) {
                            if (!val.test(headers[header])) {
                                throw new Error('Expected "' + expect[1] + '" matching ' + val + ', got "' + headers[header] + '"' + "\n" + expect[3]);
                            }
                        } else {
                            if (header === "location") {
                                var actual = headers[header];
                                if (!comb.deepEqual(actual, val)
                                    && !comb.deepEqual(actual, this._baseUrl + val)
                                    && !comb.deepEqual(actual, this._baseUrl.replace(/^http[s]?:/, "") + val)) {
                                    throw new Error([
                                        'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                    ].join("") + "\n" + expect[3]);
                                }
                            } else if (!comb.deepEqual(headers[header.toLowerCase()], val)) {
                                throw new Error([
                                    'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                ].join("") + "\n" + expect[3]);
                            }
                        }
                    } else {
                        throw new Error('Expected "' + expect[1] + '" header field' + "\n" + expect[3]);
                    }
                    break;
                case "body":
github doug-martin / super-request / index.js View on Github external
var json;
                        try {
                            json = comb.isString(body) ? JSON.parse(body.replace(/\\n/g, "")) : body;
                        } catch (e) {
                            throw new Error("Unable to parse " + body + " to json");
                        }
                        if (!comb.deepEqual(json, val)) {
                            throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(json)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (comb.isFunction(val)) {
                        return val(body);
                    } else if (comb.isRegExp(val)) {
                        if (!val.test(body)) {
                            throw new Error(['Expected body', util.inspect(body), 'to match', util.inspect(val)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (!comb.deepEqual(body, val)) {
                        //just assert the body
                        throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(body)].join(" ") + "\n" + expect[2]);
                    }

                    break;
                case "status":
                    if (res.statusCode !== expect[1])
                        throw new Error(["Expected response status code to be", expect[1], "got", res.statusCode].join(" ") + "\n" + expect[2]);
                    break;

                }
            }, this, 1).then(function () {
                promise.callback(res, body);
github doug-martin / super-request / index.js View on Github external
}
                    } else {
                        throw new Error('Expected "' + expect[1] + '" header field' + "\n" + expect[3]);
                    }
                    break;
                case "body":
                    val = expect[1];
                    if (comb.isHash(val)) {
                        //the body should be json
                        var json;
                        try {
                            json = comb.isString(body) ? JSON.parse(body.replace(/\\n/g, "")) : body;
                        } catch (e) {
                            throw new Error("Unable to parse " + body + " to json");
                        }
                        if (!comb.deepEqual(json, val)) {
                            throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(json)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (comb.isFunction(val)) {
                        return val(body);
                    } else if (comb.isRegExp(val)) {
                        if (!val.test(body)) {
                            throw new Error(['Expected body', util.inspect(body), 'to match', util.inspect(val)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (!comb.deepEqual(body, val)) {
                        //just assert the body
                        throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(body)].join(" ") + "\n" + expect[2]);
                    }

                    break;
                case "status":
                    if (res.statusCode !== expect[1])