Skip to content

Commit

Permalink
Legacy fix default clearing on input (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboe026 committed Oct 24, 2022
1 parent b41b898 commit d53072c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/input.js
Expand Up @@ -101,7 +101,7 @@ class InputPrompt extends Base {
*/

onKeypress() {
this.state = 'touched';
this.status = 'touched';

this.render();
}
Expand Down
1 change: 1 addition & 0 deletions packages/inquirer/package.json
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"chai": "^4.3.6",
"chai-string": "^1.5.0",
"chalk-pipe": "^5.1.1",
"cmdify": "^0.0.4",
"mocha": "^9.2.2",
Expand Down
24 changes: 24 additions & 0 deletions packages/inquirer/test/specs/prompts/input.js
@@ -1,9 +1,13 @@
const { expect } = require('chai');
const chai = require('chai');
const chaiString = require('chai-string');
const ReadlineStub = require('../../helpers/readline');
const fixtures = require('../../helpers/fixtures');

const Input = require('../../../lib/prompts/input');

chai.use(chaiString);

describe('`input` prompt', () => {
beforeEach(function () {
this.fixture = { ...fixtures.input };
Expand Down Expand Up @@ -94,4 +98,24 @@ describe('`input` prompt', () => {
done();
}, 200);
});

it('should clear default on input', function (done) {
const defaultValue = 'default-string';
const input = new Input(
{
...this.fixture,
default: defaultValue,
},
this.rl
);

input.run();

this.rl.line = 'inquirer';
this.rl.input.emit('keypress');
setTimeout(() => {
expect(this.rl.output.__raw__).to.have.entriesCount(defaultValue, 1);
done();
}, 200);
});
});
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -2820,6 +2820,11 @@ caseless@~0.12.0:
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=

chai-string@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.5.0.tgz#0bdb2d8a5f1dbe90bc78ec493c1c1c180dd4d3d2"
integrity sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==

chai@^4.3.6:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
Expand Down

0 comments on commit d53072c

Please sign in to comment.