Skip to content

Commit

Permalink
Make a mockedGenerator a Generator child.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 26, 2021
1 parent 8a9baf0 commit c6e3493
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const fs = require('fs');
const path = require('path');
const sinon = require('sinon');
const Generator = require('yeoman-generator');
const adapter = require('./adapter');

/**
Expand Down Expand Up @@ -143,11 +144,13 @@ exports.mockLocalConfig = function (generator, localConfig) {
* Create a mocked generator
*/

exports.createMockedGenerator = () => {
const generator = sinon.stub();
generator.prototype.run = sinon.stub();
generator.prototype.runWithOptions = sinon.stub();
generator.prototype.queueOwnTasks = sinon.stub();
exports.createMockedGenerator = (constructor = Generator) => {
const generator = sinon.spy(constructor);
['run', 'queueTasks', 'runWithOptions', 'queueOwnTasks'].forEach(methodName => {
if (Generator.prototype[methodName]) {
generator.prototype[methodName] = sinon.stub();
}
});
return generator;
};

Expand Down

0 comments on commit c6e3493

Please sign in to comment.