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?