0

I can't understand how to use the createDummyGenerator() function when testing a generator that relies on external generators.

I have tried:

test.js:

...
return helpers.run(require.resolve('../generators/app'))
  .withGenerators([
    [helpers.createDummyGenerator(), 'license:app'],
  ])
  .then(() => {
    assert.textEqual('true', 'true')
  });
...

index.js:

...
default() {
  this.composeWith('license:app', { name: 'foo' });
}
...

This makes the test fail because it can't find a generator for license:app. I have generator-license in my package.json as a dependency.


I also tried the following:

test.js:

...
beforeEach(() => {
  jest.mock('generator-license/app', () => {
    const helpers = require('yeoman-test');
    return helpers.createDummyGenerator();
  });
}
...

index.js:

...
default() {
  this.composeWith(require.resolve('generator-license/app', { name: 'foo' }));
}
...

This doesn't mock the generator at all, and it uses the actual generator-license code, which makes the test fail because not all prompts are supplied (some are meant to be asked by the license generator)


How am I supposed to use the createDummyGenerator() helper to completely stub out the license generator?

springloaded
  • 1,079
  • 2
  • 13
  • 23

1 Answers1

0

Well, I feel like an idiot... I had a typo in another test that didn't mock the module, and that's what was making the test suite fail... Nevermind, nothing to see here :)

springloaded
  • 1,079
  • 2
  • 13
  • 23