Skip to content

Commit

Permalink
improved error message if more than one component testing plugin is l…
Browse files Browse the repository at this point in the history
…oaded
  • Loading branch information
beatfactor committed Oct 28, 2022
1 parent f2916a6 commit d6e0a34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/utils/addDetailedError.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ module.exports = function(err) {
'object globally too soon, either in your test or other Nightwatch related files';
} else if (/\.page\..+ is not a function$/.test(err.message)) {
detailedErr = '- verify if page objects are setup correctly, check "page_objects_path" in your config';
} else if (err.message.includes('browser.mountComponent is not a function')) {
detailedErr = ' - writing a component test? - make sure to install the necessary plugins (e.g. @nightwatch/react or @nightwatch/vue)';
} else if (err.message.includes('.mountComponent() is already defined.')) {
detailedErr = ' - running component tests? loading multiple plugins together is not supported.';
err.help = [
'check your nightwatch config file (e.g. nightwatch.conf.js) and inspect the line with "plugins": [...]',
'make sure to load only the plugin for the intended framework (e.g. either load @nightwatch/react or @nightwatch/vue, but not both together)'
];

err.link = 'https://nightwatchjs.org/guide/concepts/component-testing.html';
} else if (err.message.includes('browser.mountComponent is not a function')) {
detailedErr = ' - writing an ES6 async test case? - keep in mind that commands return a Promise; \n - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.';
} else if (/\w is not a function$/.test(err.message)) {
detailedErr = ' - writing an ES6 async test case? - keep in mind that commands return a Promise; \n - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class Logger {
return ' ' + message.join('\n ');
}

if (!showStack && !this.isAssertionError(error)) {
if (!showStack && !this.isAssertionError(error) && !error.help) {
return '\n' + boxen(`${message.join('\n')}\n`, {padding: 1, borderColor: 'red'}) + '\n';
}

Expand Down

0 comments on commit d6e0a34

Please # to comment.