classTestObject{constructor(value){if(value===null||value===undefined){thrownewError('Expectavalue!');}}}describe('testtheconstructor',()=>{test('itworks',()=>{expect(()=>{newTestObject();}).toThrow();});test('notwork',()=>{expect(newTestObject()).toThrow();});});此处有2个测试用例,一个有效,另一个无效。notwork的失败消
这是我的错误代码:FAILbuild/__test__/FuncOps.CheckFunctionExistenceByString.test.js●expect(CheckFunctionExistenceByStr('anystring','FunctionThatDoesNotExistsInString')).toThrow();FunctionFunctionThatDoesNotExistsInStringdoesnotexistsinstring.atCheckFunctionExistenceByStr(build/FuncOps.js:35:15)atObject.(
文档位于https://github.com/pivotal/jasmine/wiki/Matchers包括以下内容:expect(function(){fn();}).toThrow(e);如thisquestion中所述,下面的代码不起作用,因为我们想传递一个函数对象给expect,而不是调用fn()的结果:expect(fn()).toThrow(e);以下是否有效?expect(fn).toThrow(e);如果我用doIt方法定义了一个对象thing,下面的操作是否有效?expect(thing.doIt).toThrow(e);(如果是这样,有没有办法将参数传递给doIt方
文档位于https://github.com/pivotal/jasmine/wiki/Matchers包括以下内容:expect(function(){fn();}).toThrow(e);如thisquestion中所述,下面的代码不起作用,因为我们想传递一个函数对象给expect,而不是调用fn()的结果:expect(fn()).toThrow(e);以下是否有效?expect(fn).toThrow(e);如果我用doIt方法定义了一个对象thing,下面的操作是否有效?expect(thing.doIt).toThrow(e);(如果是这样,有没有办法将参数传递给doIt方