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

Test generators private methods #1134

Closed
makbol opened this issue Oct 23, 2019 · 2 comments
Closed

Test generators private methods #1134

makbol opened this issue Oct 23, 2019 · 2 comments

Comments

@makbol
Copy link

makbol commented Oct 23, 2019

Say I wrote my custom generator like this

class extends Generator {
  writing() {
    this._private_method();
  }

  _private_method() {
    console.log('private hey');
  }
}

with use of private methods according to doc recommendation

I'd like to unit test only _private_method()

I tried to setup test like:

const Generator = require('../generators/app');
const generator = new Generator();

describe('generator:_private_method', () => {
  it('returns correct output', () => {
    assert(generator._private_method());
  });
});

but I get error TypeError: Cannot use 'in' operator to search for 'help' in undefined

@SBoudrias
Copy link
Member

The Generator class expect arguments to be passed in. It requires an instance of yeoman-environment to work properly.

Something like const generator = environment.createEnv().instantiate(Generator).

This isn't really a public interface, so you might need to dig through the environment code to get it to work properly.

@makbol
Copy link
Author

makbol commented Oct 29, 2019

Thank you @SBoudrias 🙏

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

No branches or pull requests

2 participants