@@ -8,20 +8,42 @@ test("FileAttachments is exported by stdlib", t => {
8
8
} ) ;
9
9
10
10
test ( "FileAttachment ensures that URLs are strings" , async t => {
11
- const fileAttachments = FileAttachments ( ( name ) =>
11
+ const FileAttachment = FileAttachments ( ( name ) =>
12
12
new URL ( `https://example.com/${ name } .js` )
13
13
) ;
14
- const file = fileAttachments ( "filename" ) ;
14
+ const file = FileAttachment ( "filename" ) ;
15
15
t . equal ( file . constructor . name , "FileAttachment" ) ;
16
16
t . equal ( await file . url ( ) , "https://example.com/filename.js" ) ;
17
17
t . end ( ) ;
18
18
} ) ;
19
19
20
+ test ( "FileAttachment returns instances of FileAttachment" , async t => {
21
+ const FileAttachment = FileAttachments ( ( name ) =>
22
+ new URL ( `https://example.com/${ name } .js` )
23
+ ) ;
24
+ const file = FileAttachment ( "filename" ) ;
25
+ t . true ( file instanceof FileAttachment ) ;
26
+ t . end ( ) ;
27
+ } ) ;
28
+
29
+ test ( "FileAttachment cannot be used as a constructor" , async t => {
30
+ const FileAttachment = FileAttachments ( ( name ) =>
31
+ new URL ( `https://example.com/${ name } .js` )
32
+ ) ;
33
+ try {
34
+ new FileAttachment ( "filename" ) ;
35
+ t . fail ( ) ;
36
+ } catch ( error ) {
37
+ t . equal ( error . message , "FileAttachment is not a constructor" ) ;
38
+ }
39
+ t . end ( ) ;
40
+ } ) ;
41
+
20
42
test ( "FileAttachment works with Promises that resolve to URLs" , async t => {
21
- const fileAttachments = FileAttachments ( async ( name ) =>
43
+ const FileAttachment = FileAttachments ( async ( name ) =>
22
44
new URL ( `https://example.com/${ name } .js` )
23
45
) ;
24
- const file = fileAttachments ( "otherfile" ) ;
46
+ const file = FileAttachment ( "otherfile" ) ;
25
47
t . equal ( file . constructor . name , "FileAttachment" ) ;
26
48
t . equal ( await file . url ( ) , "https://example.com/otherfile.js" ) ;
27
49
t . end ( ) ;
0 commit comments