I need to add some type checker to the Jest. It must look somehow like expect(someVar).toBeType('string')
and expect(someVar).toBeType(['string', 'object'])
.
I tried to add some checker-helper, but it looks a little bit ugly.
const toBeType = (arg:any, type:string) => {
const argType = typeof arg;
if (argType !== type)
throw new Error(`Expected '${type}' but got '${argType}' for 'arg'.`);
};
I want to add similar functionality to the jest
namespace to have ability to call type checker like expect(someVar).toBeType('boolean')
.
Aucun commentaire:
Enregistrer un commentaire