1

我正在尝试通过抛出错误进行测试。

 test('throws', t => {
    t.throws(() => { 
    valid(1) }, "Error can't put number");
 });

所以有效的是函数,当我输入数字时,我想抛出错误。现在它给了我 AssertionError: Missing expected exception (err)..

不知道我做错了什么。

4

1 回答 1

2

t.throws() asserts that the function you pass it throws an error. You say:

when I put number I want to throw the error

t.throws() doesn't change the behavior of valid(1). If it doesn't already throw, then your test will fail with an AssertionError.

于 2017-01-31T17:09:33.160 回答