在测试依赖于外部生成器的生成器时,我无法理解如何使用createDummyGenerator()函数。
我试过了:
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' });
}
...这会导致测试失败,因为它找不到license:app的生成器。我的package.json中有生成器许可证作为依赖项。
我还尝试了以下几种方法:
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' }));
}
...这根本不模拟生成器,它使用实际的生成器-许可证代码,这会导致测试失败,因为没有提供所有提示(其中一些是由许可证生成器询问的)
我应该如何使用createDummyGenerator()帮助器来完全清除许可证生成器?
发布于 2018-08-14 05:57:36
我觉得自己像个笨蛋..。我在另一个没有模拟模块的测试中有一个拼写错误,这就是导致测试套件失败的原因……不要紧,这里没什么可看的:)
https://stackoverflow.com/questions/51830589
复制相似问题