@@ -12,7 +12,7 @@ import { expect } from 'chai';
12
12
13
13
import { CommandRegistry } from '@lumino/commands' ;
14
14
15
- import { JSONObject } from '@lumino/coreutils' ;
15
+ import { JSONObject , ReadonlyJSONObject } from '@lumino/coreutils' ;
16
16
17
17
import { Platform } from '@lumino/domutils' ;
18
18
@@ -329,7 +329,7 @@ describe('@lumino/commands', () => {
329
329
} ) ;
330
330
331
331
describe ( '#describedBy()' , ( ) => {
332
- it ( 'should get the description for a specific command' , ( ) => {
332
+ it ( 'should get the description for a specific command' , async ( ) => {
333
333
const description = {
334
334
args : {
335
335
properties : { } ,
@@ -344,16 +344,79 @@ describe('@lumino/commands', () => {
344
344
describedBy : description
345
345
} ;
346
346
registry . addCommand ( 'test' , cmd ) ;
347
- expect ( registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
347
+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
348
348
} ) ;
349
349
350
- it ( 'should return an empty description if the command is not registered' , ( ) => {
351
- expect ( registry . describedBy ( 'foo' ) ) . to . deep . equal ( { args : null } ) ;
350
+ it ( 'should accept a function' , async ( ) => {
351
+ const description = {
352
+ args : {
353
+ properties : { } ,
354
+ additionalProperties : false ,
355
+ type : 'object'
356
+ }
357
+ } ;
358
+
359
+ let cmd = {
360
+ execute : ( args : JSONObject ) => {
361
+ return args ;
362
+ } ,
363
+ describedBy : ( ) => description
364
+ } ;
365
+ registry . addCommand ( 'test' , cmd ) ;
366
+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
352
367
} ) ;
353
368
354
- it ( 'should default to an empty description for a command' , ( ) => {
369
+ it ( 'should accept an asynchronous function' , async ( ) => {
370
+ const description = {
371
+ args : {
372
+ properties : { } ,
373
+ additionalProperties : false ,
374
+ type : 'object'
375
+ }
376
+ } ;
377
+
378
+ let cmd = {
379
+ execute : ( args : JSONObject ) => {
380
+ return args ;
381
+ } ,
382
+ describedBy : ( ) => Promise . resolve ( description )
383
+ } ;
384
+ registry . addCommand ( 'test' , cmd ) ;
385
+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
386
+ } ) ;
387
+
388
+ it ( 'should accept args' , async ( ) => {
389
+ const description = {
390
+ properties : { } ,
391
+ additionalProperties : false ,
392
+ type : 'object'
393
+ } ;
394
+
395
+ let cmd = {
396
+ execute : ( args : JSONObject ) => {
397
+ return args ;
398
+ } ,
399
+ describedBy : ( args : ReadonlyJSONObject ) => {
400
+ return {
401
+ args
402
+ } ;
403
+ }
404
+ } ;
405
+ registry . addCommand ( 'test' , cmd ) ;
406
+ expect (
407
+ await registry . describedBy ( 'test' , description as any )
408
+ ) . to . deep . equal ( { args : description } ) ;
409
+ } ) ;
410
+
411
+ it ( 'should return an empty description if the command is not registered' , async ( ) => {
412
+ expect ( await registry . describedBy ( 'foo' ) ) . to . deep . equal ( { args : null } ) ;
413
+ } ) ;
414
+
415
+ it ( 'should default to an empty description for a command' , async ( ) => {
355
416
registry . addCommand ( 'test' , NULL_COMMAND ) ;
356
- expect ( registry . describedBy ( 'test' ) ) . to . deep . equal ( { args : null } ) ;
417
+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( {
418
+ args : null
419
+ } ) ;
357
420
} ) ;
358
421
} ) ;
359
422
0 commit comments