Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
This repository was archived by the owner on May 26, 2025. It is now read-only.

Combining chai-subset and chai-as-promised #69

@bkimminich

Description

@bkimminich

I hope to be able to replace some ugly

  it('should consist of one object pushed into flagKeys.results per challenge', function () {
    return expect(generateData(challenges, options.noTextHints, options.noHintUrls, '')).to.eventually.deep.include(
      {
        flagKeys: {
          results: [
            { id: 1, chal: 1, flag: '958c64658383140e7d08d5dee091009cc0eafc1f', type: 'static', key_type: 'static', data: null }, ...
          ]
        }
      })
  })

assertions (which need to specify all the object properties that I don't even care about) with

  it('should consist of one object pushed into flagKeys.results per challenge', function () {
    return expect(generateData(challenges, options.noTextHints, options.noHintUrls, '')).to.eventually.containSubset(
      {
        flagKeys: {
          results: [
            { id: 1, chal: 1, flag: '958c64658383140e7d08d5dee091009cc0eafc1f' }, ...
          ]
        }
      })
  })

checks. Unfortunately that does not work, because that eventually-thing is a promise with the actual compare value nested inside. This gives me errors like:

 AssertionError: expected { Object (_bitField, _fulfillmentHandler0, ...) } to contain subset { Object (flagKeys) }
      + expected - actual

       {
      -  "_bitField": 33554432
      -  "_fulfillmentHandler0": [undefined]
      -  "_promise0": [undefined]
      -  "_receiver0": [undefined]
      -  "_rejectionHandler0": {
      -    "challenges": {
      -      "results": [...]
      -    }
      -    "flagKeys": {
      -      "results": [
      -        {
      -          "chal": 1
      -          "data": [null]
      -          "flag": "958c64658383140e7d08d5dee091009cc0eafc1f"
      -          "id": 1
      -          "key_type": "static"
      -          "type": "static"
      -        } ...
      -      ]
      -    }
      -    "hints": {
      -      "results": []
      -    }
      +  "flagKeys": {
      +    "results": [
      +      {
      +        "chal": 1
      +        "data": [null]
      +        "flag": "958c64658383140e7d08d5dee091009cc0eafc1f"
      +      } ...
      +    ]
         }
       }

      at Proxy.<anonymous> (node_modules\chai-subset\lib\chai-subset.js:20:30)
      at Proxy.methodWrapper (node_modules\chai\lib\chai\utils\addMethod.js:57:25)
      at Context.<anonymous> (test\unit\generateData-spec.js:38:104)

Using to.eventually.deep.containSubset does not work either. You can find the original unit test here: https://github.com/bkimminich/juice-shop-ctf/blob/develop/test/unit/generateData-spec.js#L37-L76

Thanks in advance for your help/hints! Btw, merry 🎄 to you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions