@@ -11,7 +11,6 @@ describe('home route', () => {
1111 let adapter ;
1212
1313 beforeEach ( async function ( ) {
14- this . sandbox = sinon . createSandbox ( ) ;
1514 this . env = await fakeEnv ( ) ;
1615 adapter = new TestAdapter ( ) ;
1716 this . router = new Router ( { adapter, env : this . env } ) ;
@@ -26,32 +25,29 @@ describe('home route', () => {
2625 this . router . registerRoute ( 'update' , this . updateRoute ) ;
2726 } ) ;
2827
29- afterEach ( function ( ) {
30- this . sandbox . restore ( ) ;
31- } ) ;
32-
3328 it ( 'allow going to help' , async function ( ) {
34- this . sandbox . stub ( adapter , 'prompt' ) . returns ( Promise . resolve ( { whatNext : 'help' } ) ) ;
35- await this . router . navigate ( 'home' ) . then ( ( ) => {
36- sinon . assert . calledOnce ( this . helpRoute ) ;
37- } ) ;
29+ adapter . addAnswers ( { whatNext : 'help' } ) ;
30+
31+ await this . router . navigate ( 'home' ) ;
32+
33+ sinon . assert . calledOnce ( this . helpRoute ) ;
3834 } ) ;
3935
4036 it ( 'allow going to install' , async function ( ) {
41- this . sandbox . stub ( adapter , 'prompt' ) . returns ( Promise . resolve ( { whatNext : 'install' } ) ) ;
42- await this . router . navigate ( 'home' ) . then ( ( ) => {
43- sinon . assert . calledOnce ( this . installRoute ) ;
44- } ) ;
37+ adapter . addAnswers ( { whatNext : 'install' } ) ;
38+
39+ await this . router . navigate ( 'home' ) ;
40+
41+ sinon . assert . calledOnce ( this . installRoute ) ;
4542 } ) ;
4643
4744 it ( 'does not display update options if no generators is installed' , async function ( ) {
4845 this . router . generator = [ ] ;
49- this . sandbox . stub ( adapter , 'prompt' ) . callsFake ( prompts => {
50- assert . strictEqual ( _ . map ( prompts [ 0 ] . choices , 'value' ) . includes ( 'update' ) , false ) ;
51- return Promise . resolve ( { whatNext : 'exit' } ) ;
52- } ) ;
46+ adapter . addAnswers ( { whatNext : 'exit' } ) ;
5347
5448 await this . router . navigate ( 'home' ) ;
49+
50+ assert . strictEqual ( _ . map ( adapter . calls [ 0 ] . question . choices , 'value' ) . includes ( 'update' ) , false ) ;
5551 } ) ;
5652
5753 it ( 'show update menu option if there is installed generators' , async function ( ) {
@@ -62,14 +58,12 @@ describe('home route', () => {
6258 updateAvailable : false ,
6359 } ] ;
6460
65- this . sandbox . stub ( adapter , 'prompt' ) . callsFake ( prompts => {
66- assert ( _ . map ( prompts [ 0 ] . choices , 'value' ) . includes ( 'update' ) ) ;
67- return Promise . resolve ( { whatNext : 'update' } ) ;
68- } ) ;
61+ adapter . addAnswers ( { whatNext : 'update' } ) ;
6962
70- await this . router . navigate ( 'home' ) . then ( ( ) => {
71- sinon . assert . calledOnce ( this . updateRoute ) ;
72- } ) ;
63+ await this . router . navigate ( 'home' ) ;
64+
65+ assert ( _ . map ( adapter . calls [ 0 ] . question . choices , 'value' ) . includes ( 'update' ) ) ;
66+ sinon . assert . calledOnce ( this . updateRoute ) ;
7367 } ) ;
7468
7569 it ( 'list runnable generators' , async function ( ) {
@@ -80,19 +74,17 @@ describe('home route', () => {
8074 updateAvailable : false ,
8175 } ] ;
8276
83- this . sandbox . stub ( adapter , 'prompt' ) . callsFake ( prompts => {
84- assert . strictEqual ( prompts [ 0 ] . choices [ 1 ] . value . generator , 'unicorn:app' ) ;
85- return Promise . resolve ( {
86- whatNext : {
87- method : 'run' ,
88- generator : 'unicorn:app' ,
89- } ,
90- } ) ;
77+ adapter . addAnswers ( {
78+ whatNext : {
79+ method : 'run' ,
80+ generator : 'unicorn:app' ,
81+ } ,
9182 } ) ;
9283
93- await this . router . navigate ( 'home' ) . then ( ( ) => {
94- sinon . assert . calledWith ( this . runRoute , this . router , 'unicorn:app' ) ;
95- } ) ;
84+ await this . router . navigate ( 'home' ) ;
85+
86+ assert . strictEqual ( adapter . calls [ 0 ] . question . choices [ 1 ] . value . generator , 'unicorn:app' ) ;
87+ sinon . assert . calledWith ( this . runRoute , this . router , 'unicorn:app' ) ;
9688 } ) ;
9789
9890 it ( 'show update available message behind generator name' , async function ( ) {
@@ -103,11 +95,10 @@ describe('home route', () => {
10395 updateAvailable : true ,
10496 } ] ;
10597
106- this . sandbox . stub ( adapter , 'prompt' ) . callsFake ( prompts => {
107- assert ( prompts [ 0 ] . choices [ 1 ] . name . includes ( '♥ Update Available!' ) ) ;
108- return Promise . resolve ( { whatNext : 'exit' } ) ;
109- } ) ;
98+ adapter . addAnswers ( { whatNext : 'exit' } ) ;
11099
111100 await this . router . navigate ( 'home' ) ;
101+
102+ assert ( adapter . calls [ 0 ] . question . choices [ 1 ] . name . includes ( '♥ Update Available!' ) ) ;
112103 } ) ;
113104} ) ;
0 commit comments