Testing yoman composeWith

I am trying to test the generator creation script. In my generator, I call a subgenerator if a specific prompt returns true

if(this.bar){ this.composeWith('foo:bar', {}); } 

I obviously check the sub-generator of the bar separately. However, I would like to have a statement for this composeWith () that was called. And I suppose that the problem is more in my skills than in the examination documents, but I have no idea how to do this. I understand that I need a spy and a stub. But the documents just list the functions, and the tests for the omen generator itself are just mental (I tried to reproduce their steps, but they mainly use mannequins for everything, and I just need to drown out the sub-generator).

Any help would be really appreciated. Thanks.

+5
source share
1 answer

I admit that the documentation on this issue is not enough, and we could improve it.

Here is a simple example of how you can use a spy to check your subgenerator:

 var generators = require('yeoman-generator').generators; var assert = require('yeoman-generator').assert; before(function (done) { this.spy = sinon.spy(); var Dummy = generators.Base.extend({ exec: this.spy }); helpers.run('your/generator') .withGenerators([ [Dummy, 'foo:bar'] ]) .on('end', done); }); // Then in your assertions it('run the sub-generator', function () { assert(this.spy.calledOnce); }); 
+5
source

Source: https://habr.com/ru/post/1209862/


All Articles