我在使用的jest匹配器的StencilJS中进行了一个单元测试。当我运行测试时,它抛出了一个错误:
TypeError: Right-hand side of 'instanceof' is not an object
at checkHtmlElement (node_modules/@testing-library/jest-dom/dist/utils.js:61:69)
at Object.toHaveFormValues (node_modules/@testing-library/jest-dom/dist/to-have-form-val
我正在尝试使用jest和react测试库对自定义钩子进行单元测试,在这种情况下抛出错误,但我无法捕获实际的错误消息,以下是我到目前为止的代码:
我的第一个钩子:
import react from 'react';
const useFirstHook = () => {
//I will add conditional logic later
throw new Error('my custom error is thrown')
const test1 = 'I am test 1';
retur
我正试图为我的单元测试项目集成jest。
我遵循了的指示。
当我运行时,作为ENOENT: no such file or directory, open 'E:\source-code\packages\core\src\view\ng_module.ts',我面临一个奇怪的错误。
我的文件夹结构没有一个名为package.After的文件夹,我发现packages\core\src\view\ng_module.ts'是由npm包使用的(角:P)
我不知道这个错误是如何被抛出的,当我穿越业力时,这个错误不会发生。
这是我给jest "jest"
问题
我使用nuxt1.4进行路由,使用Jest进行单元测试。我的应用程序不会抛出错误,而且看起来工作得很好。然而,当运行我的单元测试npm run unit (运行玩笑)时,它会在终端[Vue warn]: Unknown custom element: <nuxt-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.中抛出一个错误。
期望
我希望它不会抛出这个错误,因为我的应用程序正在工
我在一个节点包类方法中使用了XMLSerializer类。当使用jest编写单元测试用例时,会抛出XMLSerializer is not undefined错误。因为这是浏览器原生的,所以不能有任何包。 即使我在网上搜索,也很少找到关于using a new jsdom和创建XMLSerializer原型的建议。 没有找到合适的解决方案,甚至没有帖子。
我是单元测试的新手,我想用方法测试一个组件,在这个方法中,我使用this.random函数,jQuery和Jest。
我想测试是否调用了openPost方法?
当我得到一个测试时,它会抛出错误this.$ is not a function和this.random is not a function。
我怎么写测试?
构成部分:
<template>
<div @click="openPost('note')" class="ml-3 text-center pointer noteBtn">
<
我在我的单元测试中使用jest,当我的代码抛出一个意外的异常时,我有一个问题,jest不能处理它。 例如: async function func() {
throw new Error('ERROR');
}
test('test', async () => {
await func();
}); 我希望jest能告诉我哪里有异常,但我得到的结果是: TypeError: jasmine.Spec.isPendingSpecException is not a function
at returnValue.then.error
我有npm和webpack的react应用程序。我正在尝试将单元测试添加到其中。
我使用的是index.html中包含的CDN中的jQuery,而不是node模块。
我在一个添加了单元测试用例的组件Test1中使用了jQuery。
现在,当我执行测试用例时,我收到错误消息,说ReferenceError: $ is not defined我知道Jest不能解决这个问题,因为我没有在组件中导入jQuery导入。
问题是,如何让Jest了解外部JS?
我有一个axios应用程序接口,我将其默认超时设置为5000ms (5秒)。我想对存根进行单元测试,它会抛出超时异常/承诺拒绝,错误代码为ECONNABORTED。但是,每当我尝试在使用moxios模拟之后调用api时,我都会得到这样的错误:Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
PS:使用Jest作为我的测试运行。
我使用jest为我的应用程序运行集成测试。它似乎工作得很好,但当我再次运行它时,我总是得到一个错误。 以下是该错误的缩写版本... Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPSERVERWRAP
10 | const port = process.env.PORT || 3000
11 |
> 12 | module.exports = app.listen(port, () => logger.info(`Listening on
我正在尝试用Jest测试以下模块:
// myModule.js
export function otherFn() {
console.log('do something');
}
export function testFn() {
otherFn();
// do other things
}
如上所示,它导出了一些命名函数,重要的是testFn使用了otherFn。
在Jest中,当我为testFn编写单元测试时,我想模拟otherFn函数,因为我不希望otherFn中的错误影响我的testFn单元测试。我的问题是,我不确定最好的方法:
// myMo
我正在尝试在react应用程序中为我的商店编写一个单元测试。
单元测试看起来像这样:
import FRIENDS from '../../constants/friends';
import FriendsStore from '../friends_store';
jest.dontMock('../../constants/friends');
jest.dontMock('../friends_store');
describe('FriendsStore', () => {
let A