【发布时间】:2018-03-16 11:30:26
【问题描述】:
我有以下功能:
export const getRotation = (elementId, position) => {
if (typeof elementId !== 'string') {
throw new TypeError('Argument "elementId" is not a string!');
}
if (typeof position !== 'number') {
throw new TypeError('Argument "position" is not a number!');
}
// ...
};
有没有一种方法可以正确地测试这个函数的参数,而不必遍历每个数据类型?像这样:
it('should throw if argument "elementId" is an object', () => {
const elementId = {};
expect(() => {
getRotation(elementId);
}).toThrow();
});
it('should throw if argument "elementId" is boolean', () => {
const elementId = true;
expect(() => {
getRotation(elementId);
}).toThrow();
});
// ...
【问题讨论】:
标签: node.js unit-testing jestjs