@@ -13,10 +13,37 @@ vi.mock("@clack/prompts", () => ({
13
13
} ) ) ;
14
14
15
15
describe ( "getPrefillOrPromptedValue" , ( ) => {
16
- it ( "provides no placeholder when one is not provided" , async ( ) => {
16
+ it ( "returns the placeholder when auto is true and it exists" , async ( ) => {
17
+ const value = "Test Value" ;
18
+
19
+ const actual = await getPrefillOrPromptedOption (
20
+ "field" ,
21
+ true ,
22
+ "Input message." ,
23
+ vi . fn ( ) . mockResolvedValue ( value ) ,
24
+ ) ;
25
+
26
+ expect ( actual ) . toEqual ( { error : undefined , value } ) ;
27
+ } ) ;
28
+
29
+ it ( "returns an error when auto is true and no placeholder exists" , async ( ) => {
30
+ const actual = await getPrefillOrPromptedOption (
31
+ "field" ,
32
+ true ,
33
+ "Input message." ,
34
+ vi . fn ( ) . mockResolvedValue ( undefined ) ,
35
+ ) ;
36
+
37
+ expect ( actual ) . toEqual ( {
38
+ error : "Could not infer a default value for field." ,
39
+ value : undefined ,
40
+ } ) ;
41
+ } ) ;
42
+
43
+ it ( "provides no placeholder when one is not provided and auto is false" , async ( ) => {
17
44
const message = "Test message" ;
18
45
19
- await getPrefillOrPromptedOption ( message ) ;
46
+ await getPrefillOrPromptedOption ( "Input message." , false , message ) ;
20
47
21
48
expect ( mockText ) . toHaveBeenCalledWith ( {
22
49
message,
@@ -25,36 +52,38 @@ describe("getPrefillOrPromptedValue", () => {
25
52
} ) ;
26
53
} ) ;
27
54
28
- it ( "provides the placeholder's awaited return when a placeholder function is provided" , async ( ) => {
55
+ it ( "provides the placeholder's awaited return when a placeholder function is provided and auto is false " , async ( ) => {
29
56
const message = "Test message" ;
30
57
const placeholder = "Test placeholder" ;
31
58
32
- await getPrefillOrPromptedOption (
59
+ const actual = await getPrefillOrPromptedOption (
60
+ "field" ,
61
+ false ,
33
62
message ,
34
63
vi . fn ( ) . mockResolvedValue ( placeholder ) ,
35
64
) ;
36
65
37
- expect ( mockText ) . toHaveBeenCalledWith ( {
38
- message,
39
- placeholder,
40
- validate : expect . any ( Function ) ,
66
+ expect ( actual ) . toEqual ( {
67
+ error : undefined ,
68
+ value : placeholder ,
41
69
} ) ;
70
+ expect ( mockText ) . not . toHaveBeenCalled ( ) ;
42
71
} ) ;
43
72
44
- it ( "validates entered text when it's not blank" , async ( ) => {
73
+ it ( "validates entered text when it's not blank and auto is false " , async ( ) => {
45
74
const message = "Test message" ;
46
75
47
- await getPrefillOrPromptedOption ( message ) ;
76
+ await getPrefillOrPromptedOption ( "Input message." , false , message ) ;
48
77
49
78
const { validate } = ( mockText . mock . calls [ 0 ] as [ Required < TextOptions > ] ) [ 0 ] ;
50
79
51
80
expect ( validate ( message ) ) . toBeUndefined ( ) ;
52
81
} ) ;
53
82
54
- it ( "invalidates entered text when it's blank" , async ( ) => {
83
+ it ( "invalidates entered text when it's blank and auto is false " , async ( ) => {
55
84
const message = "" ;
56
85
57
- await getPrefillOrPromptedOption ( message ) ;
86
+ await getPrefillOrPromptedOption ( "Input message." , false , message ) ;
58
87
59
88
const { validate } = ( mockText . mock . calls [ 0 ] as [ Required < TextOptions > ] ) [ 0 ] ;
60
89
0 commit comments