Giter Club home page Giter Club logo

chai-exclude's Introduction

Medium Logo Twitter Logo LinkedIn Logo

chai-exclude's People

Contributors

andykais avatar blastrock avatar bryanjhv avatar codacy-badger avatar dependabot[bot] avatar jturinetti avatar kurtcorbett avatar marcogrcr avatar mathroc avatar mesaugat avatar quentinvernot avatar safalpandey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chai-exclude's Issues

Support for excluding property in nested Array

expect(interception.request.body).excludingEvery('streetnumber').deep.equal({ kenmerk: KENMERK, aangevraagdePercelen: [ { type: 'PERCEEL', adres: { straatnaam: 'street', streetnumber: 'randomSomething' } } ] });

we would expect streetnumber to be excluded in all aangevraagdePercelen

Deep equal comparison of MongoDB Object Ids always passes when using .excluding

The test below always passes. If you remove the .excluding, it always fails.
mongodb - 4.17.1
mongoose - 6.12.3
chai - 4.3.10
chai-exclude - 2.1.0

describe('ObjectId comparison', () => {
  it('Compare ObjectIds with .excluding', () => {
    expect(new ObjectId()).excluding('anything').to.deep.equal(new ObjectId())
  })
})

I believe the culprit is fclone, which appears to strip out the internals of ObjectIds

Exclude specific nested key and not every?

Hello

Cool project, thank you very much for sharing!
Is there a way for excluding a specific nested key? not every key.

Instead of this:

expect({a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'})
    .excludingEvery('c')
    .to.deep.equal(({a: 'aa', b: { a: 'hey'}}));

Something like this:

expect({a: 'aa', b: { a: 'hey', c: 'dd' }, c: 'dd1'})
    .excluding('b.c')
    .to.deep.equal(({a: 'aa', b: { a: 'hey'}, c: 'dd1'}));

exclude property path

sometime I might want to ignore properties only at certain level, eg:

expect({
  id: 123,
  a: {
    id: 345,
    b: "c",
  }
}).excludingPath(["a", "id"]).to.deep.equals({
  id: 123,
  a: {
    b: "c",
  }
})

do you think excludingPath would be useful ? I’ve worked around it for now by not testing some properties but I’d like to make a PR sometime if you think that would be useful

Issue with eql

Hello,

If you could check this repo: https://github.com/luigidt/exclude-issue

It gives me:

mocha --recursive

  1) compare dates with exclude
  √ compare dates without exclude

  1 passing (11ms)
  1 failing

  1) compare dates with exclude:

      AssertionError: expected { a: {} } to deeply equal { a: Thu, 01 Jan 1970 00:00:00 GMT }
      + expected - actual

       {
      -  "a": {}
      +  "a": [Date: 1970-01-01T00:00:00.000Z]
       }

      at Context.<anonymous> (test\index.js:10:16)
      at processImmediate (internal/timers.js:456:21)

Node version: v12.18.4

Is this behaviour expected?

Thank you

Syntax for http response style JSON

I'm not sure how the syntax should be for this case:

Input:

{
  "success": true,
  "data": [
    { id: 1, value: "Hello", created: "2019-10-02 14:30:00" },
    { id: 2, value: "There", created: "2019-10-02 14:30:00" },
    { id: 3, value: "General", created: "2019-10-02 14:30:00" }
  ]
}

Assert:

expect(res.body).excludingEvery('created').to.eql({
  "success": true,
  "data": [
    { id: 1, value: "Hello" },
    { id: 2, value: "There" },
    { id: 3, value: "General" }
  ]
});

I ended up separating the top level, but I was wondering if there is a way to exclude in a single assert? Perhaps something like .excludingEvery('data.created')?

Separated:

expect(res.body.success).to.eql(true);
expect(res.body.data).excludingEvery('created').to.eql([
    { id: 1, value: "Hello" },
    { id: 2, value: "There" },
    { id: 3, value: "General" }
]);

Module '"chai-exclude"' has no default export.ts

First: Thanks for providing this useful plugin.

Unfortunately I cannot use it in typescript. When trying to import the module via the code from your documentation

import * as chai from 'chai';
import chaiExclude from 'chai-exclude';

chai.use(chaiExclude);

Typescript complains about the default export of chai-exclude:
Module '"chai-exclude"' has no default export.ts

excludeEvery doesn't work for elements in arrays

Here's my test case:

   expect(transaction).excluding(['id', 'createdAt']).to.deep.equal({
      ...testTransaction,
      totalCredit: 10.4,
      totalDebit: 0
    })
   {
         "credits": [
           {
             "amount": 10,
      -      "id": "5a306e849db894d8cf0918d0",
             "name": "A book",
             "partyIds": [
               "123",
               "321"
             ]
           },
           {
             "amount": 0.4,
      -      "id": "5a306e849db894d8cf0918cf",
             "name": "Taxes",
             "partyIds": []
           }
         ]
}

Unless I'm missing something, it seems like the arrays are getting passed over. Using version 1.0.3

RangeError: Maximum call stack size exceeded with deepEqualExlcudingEvery

I got RangeError: Maximum call stack size exceeded with deepEqualExlcudingEvery
Deep equal working fine, without Maximum call stack size exceeded

Call:
assert.deepEqualExcludingEvery(structure, expectedStructure, ['start', 'end']);

Expected Object:

  {
    "declarations": [
      {
        "id": {
          "metadata": {
            "ignoredNode": false
          }
          "name": "abc"
          "parentNode": [Circular]
          "type": "Identifier"
        }
        "init": {
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": [Circular]
          "raw": "'cde'"
          "type": "Literal"
          "value": "cde"
          "x-verbatim-property": {
            "content": "'cde'"
            "precedence": 20
          }
        }
        "metadata": {
          "ignoredNode": false
        }
        "parentNode": {
          "declarations": [Circular]
          "kind": "var"
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": {
            "body": [
              [Circular]
            ]
            "metadata": {
              "ignoredNode": false
            }
            "parentNode": [Circular]
            "sourceType": "script"
            "type": "Program"
          }
          "type": "VariableDeclaration"
        }
        "type": "VariableDeclarator"
      }
    ]
    "kind": "var"
    "metadata": {
      "ignoredNode": false
    }
    "parentNode": {
      "body": [
        {
          "declarations": [
            {
              "id": {
                "metadata": {
                  "ignoredNode": false
                }
                "name": "abc"
                "parentNode": [Circular]
                "type": "Identifier"
              }
              "init": {
                "metadata": {
                  "ignoredNode": false
                }
                "parentNode": [Circular]
                "raw": "'cde'"
                "type": "Literal"
                "value": "cde"
                "x-verbatim-property": {
                  "content": "'cde'"
                  "precedence": 20
                }
              }
              "metadata": {
                "ignoredNode": false
              }
              "parentNode": [Circular]
              "type": "VariableDeclarator"
            }
          ]
          "kind": "var"
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": [Circular]
          "type": "VariableDeclaration"
        }
      ]
      "metadata": {
        "ignoredNode": false
      }
      "parentNode": [Circular]
      "sourceType": "script"
      "type": "Program"
    }
    "type": "VariableDeclaration"
  }

Actual Object:

  {
    "declarations": [
      {
        "end": 32
        "id": {
          "end": 24
          "metadata": {
            "ignoredNode": false
          }
          "name": "abc"
          "parentNode": [Circular]
          "start": 21
          "type": "Identifier"
        }
        "init": {
          "end": 32
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": [Circular]
          "raw": "'cde'"
          "start": 27
          "type": "Literal"
          "value": "cde"
          "x-verbatim-property": {
            "content": "'cde'"
            "precedence": 20
          }
        }
        "metadata": {
          "ignoredNode": false
        }
        "parentNode": {
          "declarations": [Circular]
          "end": 33
          "kind": "var"
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": {
            "body": [
              [Circular]
            ]
            "end": 46
            "metadata": {
              "ignoredNode": false
            }
            "parentNode": [Circular]
            "sourceType": "script"
            "start": 0
            "type": "Program"
          }
          "start": 17
          "type": "VariableDeclaration"
        }
        "start": 21
        "type": "VariableDeclarator"
      }
    ]
    "kind": "var"
    "metadata": {
      "ignoredNode": false
    }
    "parentNode": {
      "body": [
        {
          "declarations": [
            {
              "end": 32
              "id": {
                "end": 24
                "metadata": {
                  "ignoredNode": false
                }
                "name": "abc"
                "parentNode": [Circular]
                "start": 21
                "type": "Identifier"
              }
              "init": {
                "end": 32
                "metadata": {
                  "ignoredNode": false
                }
                "parentNode": [Circular]
                "raw": "'cde'"
                "start": 27
                "type": "Literal"
                "value": "cde"
                "x-verbatim-property": {
                  "content": "'cde'"
                  "precedence": 20
                }
              }
              "metadata": {
                "ignoredNode": false
              }
              "parentNode": [Circular]
              "start": 21
              "type": "VariableDeclarator"
            }
          ]
          "end": 33
          "kind": "var"
          "metadata": {
            "ignoredNode": false
          }
          "parentNode": [Circular]
          "start": 17
          "type": "VariableDeclaration"
        }
      ]
      "end": 46
      "metadata": {
        "ignoredNode": false
      }
      "parentNode": [Circular]
      "sourceType": "script"
      "start": 0
      "type": "Program"
    }
    "type": "VariableDeclaration"
  }

Add a new method `excludingEvery` which will delete all properties within an object

For a JSON object like this removing the line key should remove all line properties no matter how deep it is.

{
  "type": "Program",
  "start": 0,
  "end": 34,
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 1,
      "column": 34
    }
  },
  "comments": [],
  "range": [
    0,
    34
  ],
  "sourceType": "module",
  "body": [
    {
      "type": "ImportDeclaration",
      "start": 0,
      "end": 34,
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 34
        }
      },
      "specifiers": [
        {
          "type": "ImportDefaultSpecifier",
          "start": 7,
          "end": 16,
          "loc": {
            "start": {
              "line": 1,
              "column": 7
            },
            "end": {
              "line": 1,
              "column": 16
            }
          },
          "local": {
            "type": "Identifier",
            "start": 7,
            "end": 16,
            "loc": {
              "start": {
                "line": 1,
                "column": 7
              },
              "end": {
                "line": 1,
                "column": 16
              },
              "identifierName": "something"
            },
            "name": "something",
            "range": [
              7,
              16
            ],
            "_babelType": "Identifier"
          },
          "range": [
            7,
            16
          ],
          "_babelType": "ImportDefaultSpecifier"
        }
      ],
      "importKind": "value",
      "source": {
        "type": "Literal",
        "start": 22,
        "end": 33,
        "loc": {
          "start": {
            "line": 1,
            "column": 22
          },
          "end": {
            "line": 1,
            "column": 33
          }
        },
        "extra": {
          "rawValue": "something",
          "raw": "'something'"
        },
        "value": "something",
        "range": [
          22,
          33
        ],
        "_babelType": "StringLiteral",
        "raw": "'something'"
      },
      "range": [
        0,
        34
      ],
      "_babelType": "ImportDeclaration"
    }
  ]
}

The API will look similar to excluding.

expect(obj).excludingEvery('line').to.deep.equal(someObj);
expect(obj).excludingEvery(['line', 'column']).to.deep.equal(someObj);

Not sure how useful this is going to be but we may need it sometimes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.