Skip to content

Commit

Permalink
Fix default clearing on input (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboe026 committed Oct 17, 2022
1 parent 94d3217 commit 34a6020
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/inquirer/lib/prompts/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default 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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"devDependencies": {
"chai": "^4.3.6",
"chai-string": "^1.5.0",
"chalk-pipe": "^5.1.2",
"cmdify": "^0.0.4",
"mocha": "^10.0.0",
Expand Down
25 changes: 24 additions & 1 deletion packages/inquirer/test/specs/prompts/input.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { expect } from 'chai';
import chai, { expect } from 'chai';
import chaiString from 'chai-string';
import ReadlineStub from '../../helpers/readline.js';
import fixtures from '../../helpers/fixtures.js';

import Input from '../../../lib/prompts/input.js';

chai.use(chaiString);

describe('`input` prompt', () => {
beforeEach(function () {
this.fixture = { ...fixtures.input };
Expand Down Expand Up @@ -94,4 +97,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
Original file line number Diff line number Diff line change
Expand Up @@ -2532,6 +2532,11 @@ caniuse-lite@^1.0.30001332:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001339.tgz#f9aece4ea8156071613b27791547ba0b33f176cf"
integrity sha512-Es8PiVqCe+uXdms0Gu5xP5PF2bxLR7OBp3wUzUnuO7OHzhOfCyg3hdiGWVPVxhiuniOzng+hTc1u3fEQ0TlkSQ==

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.npmjs.org/chai/-/chai-4.3.6.tgz"
Expand Down

0 comments on commit 34a6020

Please sign in to comment.