I'm learning Jest. I am trying to test that when I create a class and the passed parameter isn't a string to throw an Error.
// class.js
export default class FooClass {
constructor(value) {
if (typeof value !== 'string') throw new Error('Value should be a String.')
this.value = value
}
}
// class.test.js
import FooClass from './class'
it('should throw an Error if the value is not a String', () => {
expect(new FooClass(123)).toThrowError('Value should be a String.')
})
Jest can pass this test, just returning Test failed.