I am using Jest for unit-testing and I want to test if the variable is an Object. Is there a better way to do it?
it('should throw an Error if options is not an Object', () => {
const error = 'Options should be an Object.'
expect(() => new Foo([])).toThrow(error)
expect(() => new Foo(123)).toThrow(error)
expect(() => new Foo('')).toThrow(error)
expect(() => new Foo(true)).toThrow(error)
expect(() => new Foo(NaN)).toThrow(error)
expect(() => new Foo(null)).toThrow(error)
expect(() => new Foo(() => {})).toThrow(error)
})
Aucun commentaire:
Enregistrer un commentaire