-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathroute-update.js
44 lines (38 loc) · 1.3 KB
/
route-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const inquirer = require('inquirer');
const Router = require('../lib/router');
const helpers = require('./helpers');
describe('update route', () => {
beforeEach(async function () {
this.sandbox = sinon.createSandbox();
this.env = await helpers.fakeEnv();
this.homeRoute = sinon.stub().returns(Promise.resolve());
this.router = new Router(this.env);
this.router.registerRoute('home', this.homeRoute);
this.crossSpawn = helpers.fakeCrossSpawn('close');
const updateRoute = proxyquire('../lib/routes/update', {
'cross-spawn': this.crossSpawn
});
this.router.registerRoute('update', updateRoute);
});
afterEach(function () {
this.sandbox.restore();
});
it('allows updating generators and return user to home screen', function () {
const generators = ['generator-cat', 'generator-unicorn'];
this.sandbox.stub(inquirer, 'prompt').returns(
Promise.resolve({generators})
);
return this.router.navigate('update').then(() => {
sinon.assert.calledWith(
this.crossSpawn,
'npm',
['install', '--global', ...generators]
);
sinon.assert.calledOnce(this.homeRoute);
sinon.assert.calledOnce(this.env.lookup);
});
});
});