-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
35 lines (28 loc) · 856 Bytes
/
test.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
import React, {useState} from 'react';
import test from 'ava';
import chalk from 'chalk';
import {render} from 'ink-testing-library';
import {spy} from 'sinon';
import ConfirmInput from '.';
const CURSOR = chalk.inverse(' ');
const ENTER = '\r';
const StatefulConfirmInput = props => {
const [value, setValue] = useState('');
return (
<ConfirmInput {...props} value={value} onChange={setValue}/>
);
};
test('render', t => {
const {lastFrame} = render(<ConfirmInput value="Yes"/>);
t.is(lastFrame(), `Yes${CURSOR}`);
});
test('return boolean on submit', t => {
const onSubmit = spy();
const {lastFrame, stdin} = render(<StatefulConfirmInput onSubmit={onSubmit}/>);
t.is(lastFrame(), CURSOR);
stdin.write('Yes');
t.is(lastFrame(), `Yes${CURSOR}`);
stdin.write(ENTER);
t.true(onSubmit.calledOnce);
t.true(onSubmit.calledWith(true));
});