【发布时间】:2019-02-13 19:35:36
【问题描述】:
我正在努力寻找如何用 jest 测试这个导出函数的解决方案。
export const scrollToError = () => {
setTimeout(() => {
const hasErrorElement = jQuery('.has-error');
if (!hasErrorElement.length) return;
jQuery('html,body').animate({
scrollTop: hasErrorElement.offset().top - 50,
}, 'slow');
}, 400);
};
我将它导入我的测试文件并尝试启动它:
import { scrollToError } from './utils';
describe('Utils', () => {
it('should scroll to error', () => {
const result = scrollToError();
expect(result).toBe(true); //added this just to force an error and got result as undefined
});
});
谁能给我一些关于如何使用这些依赖项测试代码的提示?
【问题讨论】:
标签: javascript jquery unit-testing jestjs