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

Testing when exceptions are thrown in 1.0.x #994

Closed
chrishutchinson opened this issue Jan 6, 2017 · 1 comment
Closed

Testing when exceptions are thrown in 1.0.x #994

chrishutchinson opened this issue Jan 6, 2017 · 1 comment

Comments

@chrishutchinson
Copy link

In my generator code I'm throwing an exception if a property of opts is not present, but I'm struggling to catch and test that error in my unit tests.

Any advice / suggestions would be great!

Generator:

module.exports = class extends Generator {

  constructor(args, opts) {
    super(args, opts);

    if(typeof opts.props === 'undefined') {
      throw new Error('The error message I want to assert on');
    }

    // ...
}

Test:

describe('abstracted error test', () => {

  it('throws an error', (done) => {
    helpers
      .run(generatorPath)
      .withOptions({
        props: undefined // The thing I'm expecting to find, when undefined it should error
      })
      .on('error', (e) => {
        // I'd expect to be able to make an assertion on the error here
        done();
      })
  });

});

yeoman-generator: 1.0.1
yeoman-assert: 2.2.2
yeoman-test: 1.6.0
mocha: 3.2.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2020

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Jan 1, 2020
@github-actions github-actions bot closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants