Skip to content

supertest should return response instead of @nightwatch_element #2

Description

@reallymello

In a normal SuperTest test one can save out the response to perform later assertions on or save the data for more complicated tests. When I try that it appears the response comes back as a @nightwatch_element instead so it doesn't appear that it is possible. Could that be added?

module.exports = {
  'can do a test': ({ supertest }) => {
    const response = supertest
      .request('https://petstore.swagger.io/v2')
      .get('/store/inventory/')
      .expect(200)
      .expect('Content-Type', /json/)
      .end(() => {});

    expect(response.status).to.equal(200);
  },
};
┌ ────────────────── ×  default: petStore.js  ───────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                │
│                                                                                                                                │
│    [Pet Store] Test Suite                                                                                                      │
│    ────────────────────────────────────────────                                                                                │
│    – can do a test                                                                                                             │
│     ✖ TypeError                                                                                                                │
│       Cannot read properties of undefined (reading '@nightwatch_element')                                                      │
│                                                                                                                                │
│        Error location:                                                                                                         │
│        C:\Projects\nightwatchTutorials\apiTesting\test\petStore.js:                                                            │
│        –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––                                                           │
│         8 |       .end(() => {});                                                                                              │
│         9 |                                                                                                                    │
│         10 |     expect(response.status).to.equal(200);                                                                        │
│         11 |   },                                                                                                              │
│         12 | };                                                                                                                │
│        –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––                                                           │
│                                                                                                                                │
│        Stack Trace :                                                                                                           │
│        at NightwatchAPI.expect (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\api\_loaders\static.js:233:62)     │
│        at globalExpect (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\index.js:311:29)                 │
│        at Object.can do a test (C:\Projects\nightwatchTutorials\apiTesting\test\petStore.js:10:5)                              │
│        at Context.call (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\context.js:476:35)               │
│        at TestCase.run (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\testcase.js:58:31)               │
│        at Runnable.__runFn (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\index.js:745:80)             │
│        at Runnable.run (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\runnable.js:126:21)              │
│        at TestSuite.executeRunnable (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\index.js:898:49)    │
│        at TestSuite.handleRunnable (C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\index.js:913:33)     │
│        at C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\testsuite\index.js:745:21                                │
│                                                                                                                                │
│    × default: petStore.js [Pet Store] can do a test (78ms)                                                                     │
│       Cannot read properties of undefined (reading '@nightwatch_element')                                                      │
│       TypeError: Cannot read properties of undefined (reading '@nightwatch_element')                                           │
│           at Object.can do a test (C:\Projects\nightwatchTutorials\apiTesting\test\petStore.js:10:5)                           │
│    √ Passed [ok]: .get('/store/inventory/').expect(200) ok                                                                     │
│    √ Passed [ok]: .get('/store/inventory/').expect('Content-Type', /json/) ok                                                  │
│                                                                                                                                │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

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