@@ -35,7 +35,7 @@ test('Is able to make terminal input and view in-progress stdout', async () => {
3535 resolve ( __dirname , './execute-scripts/stdio-inquirer.js' ) ,
3636 ] )
3737
38- const { cleanup , findByText} = props ;
38+ const { clear , findByText} = props ;
3939
4040 const instance = await findByText ( 'First option' )
4141
@@ -44,21 +44,48 @@ test('Is able to make terminal input and view in-progress stdout', async () => {
4444 // Windows uses ">", Linux/MacOS use "❯"
4545 expect ( await findByText ( / [ ❯ > ] O n e / ) ) . toBeTruthy ( )
4646
47- cleanup ( )
47+ clear ( )
4848
4949 fireEvent . down ( instance )
5050
5151 expect ( await findByText ( / [ ❯ > ] T w o / ) ) . toBeTruthy ( )
5252
53- cleanup ( )
53+ clear ( )
5454
5555 fireEvent . enter ( instance )
5656
5757 expect ( await findByText ( 'First option: Two' ) ) . toBeTruthy ( )
5858} )
5959
60+ test ( 'Is able to use fireEvent as function' , async ( ) => {
61+ const props = await render ( 'node' , [
62+ resolve ( __dirname , './execute-scripts/stdio-inquirer.js' ) ,
63+ ] )
64+
65+ const { clear, findByText} = props ;
66+
67+ const instance = await findByText ( 'First option' )
68+
69+ expect ( instance ) . toBeTruthy ( )
70+
71+ // Windows uses ">", Linux/MacOS use "❯"
72+ expect ( await findByText ( / [ ❯ > ] O n e / ) ) . toBeTruthy ( )
73+
74+ clear ( )
75+
76+ fireEvent ( instance , 'down' )
77+
78+ expect ( await findByText ( / [ ❯ > ] T w o / ) ) . toBeTruthy ( )
79+
80+ clear ( )
81+
82+ fireEvent ( instance , 'enter' )
83+
84+ expect ( await findByText ( 'First option: Two' ) ) . toBeTruthy ( )
85+ } )
86+
6087test ( 'fireEvent works when bound' , async ( ) => {
61- const { fireEvent : fireEventLocal , findByText, cleanup } = await render ( 'node' , [
88+ const { fireEvent : fireEventLocal , findByText, clear } = await render ( 'node' , [
6289 resolve ( __dirname , './execute-scripts/stdio-inquirer.js' ) ,
6390 ] )
6491
@@ -69,19 +96,42 @@ test('fireEvent works when bound', async () => {
6996 // Windows uses ">", Linux/MacOS use "❯"
7097 expect ( await findByText ( / [ ❯ > ] O n e / ) ) . toBeTruthy ( )
7198
72- cleanup ( ) ;
99+ clear ( ) ;
73100
74- fireEventLocal . down ( instance )
101+ fireEventLocal . down ( )
75102
76103 expect ( await findByText ( / [ ❯ > ] T w o / ) ) . toBeTruthy ( )
77104
78- fireEvent . enter ( instance )
79- fireEvent . enter ( instance )
80- cleanup ( ) ;
105+ fireEventLocal . enter ( )
106+ fireEventLocal . enter ( )
107+ clear ( ) ;
108+ } )
109+
110+ test ( 'fireEvent works when bound and used as function' , async ( ) => {
111+ const { fireEvent : fireEventLocal , findByText, clear} = await render ( 'node' , [
112+ resolve ( __dirname , './execute-scripts/stdio-inquirer.js' ) ,
113+ ] )
114+
115+ const instance = await findByText ( 'First option' )
116+
117+ expect ( instance ) . toBeTruthy ( )
118+
119+ // Windows uses ">", Linux/MacOS use "❯"
120+ expect ( await findByText ( / [ ❯ > ] O n e / ) ) . toBeTruthy ( )
121+
122+ clear ( ) ;
123+
124+ fireEventLocal ( 'down' )
125+
126+ expect ( await findByText ( / [ ❯ > ] T w o / ) ) . toBeTruthy ( )
127+
128+ fireEventLocal ( 'enter' )
129+ fireEventLocal ( 'enter' )
130+ clear ( ) ;
81131} )
82132
83133test ( 'SigTerm works' , async ( ) => {
84- const { findByText, cleanup } = await render ( 'node' , [
134+ const { findByText} = await render ( 'node' , [
85135 resolve ( __dirname , './execute-scripts/stdio-inquirer.js' ) ,
86136 ] )
87137
@@ -91,13 +141,11 @@ test('SigTerm works', async () => {
91141
92142 fireEvent . sigterm ( instance ) ;
93143
94- cleanup ( )
95-
96144 await waitFor ( ( ) => expect ( isRunning ( instance . pid ) ) . toBeFalsy ( ) )
97145} )
98146
99147test ( 'input works' , async ( ) => {
100- const { findByText, fireEvent : fireEventLocal , cleanup } = await render ( 'node' , [
148+ const { findByText, fireEvent : fireEventLocal , clear } = await render ( 'node' , [
101149 resolve ( __dirname , './execute-scripts/stdio-inquirer-input.js' ) ,
102150 ] )
103151
@@ -109,6 +157,6 @@ test('input works', async () => {
109157
110158 fireEventLocal . enter ( ) ;
111159
112- cleanup ( )
160+ clear ( )
113161} )
114162
0 commit comments