Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning error in custom command is throwing TypeError #3352

Closed
harshit-bs opened this issue Aug 22, 2022 · 0 comments · Fixed by #3353
Closed

Returning error in custom command is throwing TypeError #3352

harshit-bs opened this issue Aug 22, 2022 · 0 comments · Fixed by #3353
Assignees
Labels

Comments

@harshit-bs
Copy link
Member

harshit-bs commented Aug 22, 2022

Description of the bug/issue

So when I provide the correct API token in following custom-command everything works fine, but when I purposely use a bad Api token I get that type error.

Custom Command

module.exports = class GetEmailBody {
    async command(inboxId) {
      let returnValue;
      try {
          returnValue = await getEmail(inboxId);
      } catch (err) {
        console.error('An error occurred', err.message);
        returnValue = {
          status: -1,
          error: err.message
        }
      }
  
      return returnValue;
    }
  }
  
const getEmail = async (inboxId) => {
    const superagent = require('superagent');
    return await superagent
        .get(`https://redacted.com/api/v1/inboxes/${inboxId}/messages`)
        .set('Api-Token', 'wrongApiToken')
        .set('Content-type', 'application/json')
        .then(res => {
            return JSON.parse(res.text).length;
        }).catch(err => {
        //return err.message;
            throw new Error(err.message);
        });
}

Sample test

module.exports = {
  'should get messages': async (browser) => {
    console.log(await browser.getEmailBody(112233));
    browser.assert.expectedInboxCount(4, 112233).end();
  }
}

Error Log

 → TypeError

    Error while running "getEmailBody" command: [TypeError] instance.reportProtocolErrors is not a function
      - writing an ES6 async test case? - keep in mind that commands return a Promise; 
      - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.
    Stack Trace :
        at C:\Users\Mr\AppData\Roaming\npm\node_modules\nightwatch\lib\api\_loaders\command.js:183:60
        at processTicksAndRejections (node:internal/process/task_queues:96:5)

Nightwatch.js Version

2.3.3

NPM Version

8.16.0

Node Version

18.7.0

Browser

Chrome 104.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant