Typescript 复杂对象排序

Typescript 复杂对象排序,typescript,chai,Typescript,Chai,我正在使用计算机进行测试。 我需要测试数组是否根据属性正确排序 user.firstname 我的指令是 response.should.be.sortedBy('user.firstname'); 但柴是错的 AssertionError: expected '[null,null,null,null,null,null]' to be sorted in ascending order at Object.<anonymous> (build/test/e2e/http/ap

我正在使用计算机进行测试。 我需要测试数组是否根据属性正确排序

user.firstname
我的指令是

response.should.be.sortedBy('user.firstname');
但柴是错的

AssertionError: expected '[null,null,null,null,null,null]' to be sorted in ascending order
at Object.<anonymous> (build/test/e2e/http/applicants-api.js:591:38)
at Generator.next (<anonymous>)
at fulfilled (build/test/e2e/http/applicants-api.js:4:58)
at process._tickCallback (internal/process/next_tick.js:109:7)
AssertionError:应按升序排序“[null,null,null,null,null]”
反对。(build/test/e2e/http/api.js:591:38)
在Generator.next()处
完成时(build/test/e2e/http/applicators-api.js:4:58)
在进程中。_tick回调(内部/process/next_tick.js:109:7)

如何在第二级属性上指定排序?

这是不可能的,因为
chai sorted
从如下项获取键:
item[key]
因此在您的示例中,
item['user.firstname']
将不起作用。你可以这样做:

response.map(r => r.user).should.by.sortedBy('firstname')
当然没有你想象的那么好