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

Not possible to create custom assertion with no arguments #924

Closed
doublemarked opened this issue Apr 2, 2016 · 4 comments
Closed

Not possible to create custom assertion with no arguments #924

doublemarked opened this issue Apr 2, 2016 · 4 comments
Labels

Comments

@doublemarked
Copy link

Hello,

A bit new to Nightwatch - but we're trying to make a custom assertion which takes no arguments, and the Page Object command wrapper is naively trying to tweak the first parameter. The assertion we're building, noConsoleErrors, is not element scoped so rightly needs to parameters. It looks something like this:

exports.assertion = function(msg) {
  this.message = msg || `Testing if there are browser console errors`

  // Rest of implementation
};

Usage is like this:

page.assert.noConsoleErrors()

When called in that way (without a message), the command wrapper fails:

✖ TypeError: Cannot read property 'toString' of undefined
    at Object.noConsoleErrors (/project/path/node_modules/nightwatch/lib/page-object/command-wrapper.js:71:37)
    at Object.assertNoErrors (base.js:15:28)

Problem appears to be caused by naive assumptions about available parameters in the command wrapper: https://github.com/nightwatchjs/nightwatch/blob/master/lib/page-object/command-wrapper.js#L71

Are we doing something wrong, or is this a legitimate bug? Is there an obvious work around?

Nightwatch 0.8.18

@beatfactor
Copy link
Member

You can just use it on the main nightwatch object, instead of the page.

On Sat, Apr 2, 2016 at 11:19 AM, Heath Morrison notifications@github.com
wrote:

Hello,

A bit new to Nightwatch - but we're trying to make a custom assertion
which takes no arguments, and the Page Object command wrapper is naively
trying to tweak the first parameter. The assertion we're building,
noConsoleErrors, is not element scoped so rightly needs to parameters. It
looks something like this:

exports.assertion = function(msg) {
this.message = msg || Testing if there are browser console errors

// Rest of implementation
};

Usage is like this:

page.assert.noConsoleErrors()

When called in that way (without a message), the command wrapper fails:

✖ TypeError: Cannot read property 'toString' of undefined
at Object.noConsoleErrors (/project/path/node_modules/nightwatch/lib/page-object/command-wrapper.js:71:37)
at Object.assertNoErrors (base.js:15:28)

Problem appears to be caused by naive assumptions about available
parameters in the command wrapper:
https://github.com/nightwatchjs/nightwatch/blob/master/lib/page-object/command-wrapper.js#L71

Are we doing something wrong, or is this a legitimate bug? Is there an
obvious work around?

Nightwatch 0.8.18


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#924

@doublemarked
Copy link
Author

This is what we ended up doing, though it has the minor annoyance of breaking chaining.

@doublemarked
Copy link
Author

Wait, so is it not a bug though that the command wrapper doesn't check it's arguments?

@beatfactor
Copy link
Member

Oh yes, you're right. I misunderstood the issue.

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

No branches or pull requests

2 participants