Javascript 开玩笑地拒绝

Javascript 开玩笑地拒绝,javascript,node.js,typescript,jestjs,Javascript,Node.js,Typescript,Jestjs,我创建了这个类: export class ErrorList { public HostelNotFoundError(details: ErrorDetail): FunctionalError { return new FunctionalError('1', 'Can\'t find this hostel', details); } 在服务中: throw new ErrorList().HostelNotFoundError({} });

我创建了这个类:

export class ErrorList  {

  
    public HostelNotFoundError(details: ErrorDetail): FunctionalError {
        return new FunctionalError('1', 'Can\'t find this hostel', details);
    }
在服务中:

throw new ErrorList().HostelNotFoundError({} });
我想知道,在开玩笑的情况下,是否可以这样做:

rejects.toThrow(HostelNotFoundError);

HostelNotFoundError
不是
FunctionalError
类型,它是
ErrorList
类的一个方法,返回
FunctionalError
的新实例。因此,在单元测试中,您必须使用:

rejects.toThrow(FunctionalError);
请注意,您可以使用
toMatch
验证错误消息,或使用
toMatchObject
验证错误属性:

rejects.toMatch('Can\'t find this hostel');

实际抛出的错误不是FunctionalError吗?看看这个