我有一个React视图,它与商店通信。我已经成功地分别测试了视图和存储,但没有结合起来。
我跟踪了,但收到了TypeError。看起来Jest正在尝试将商店注册为一个组件,即使我使用了dontMock。
Using Jest CLI v0.2.0
PASS __tests__/unit/spec/stores/ViewStore-spec.js (0.248s)
FAIL __tests__/unit/spec/components/View-spec.react.js (0.942s)
undefined
● View › it defaults to zero unread
-
我正在尝试使用jest编写单元测试用例,并需要模拟以下模式。我得到了TypeError:不是一个构造函数。 Usecase :我的用例如下 MyComponent.js: import serviceRegistry from "external/serviceRegistry";
serviceRegistry.getService("modulename", "servvice").then(
service => {
let myServiceInst
我试图模拟具有静态getter的日志记录服务。
static get error(): Function {
return console.error.bind(console, 'Error: ');
}
尝试过:jest.spyOn(ConsoleLoggingService, 'error').mockImplementation(() => 'blah');
但我得到了TypeError: Cannot set property info of function ConsoleLoggingService() {}
我有一个API类,我试图在一个React应用程序中使用它。
// API file
class API {
...
}
export default API;
// Other file
import API from "utils/API";
const api = new API();
我发现了一个错误:
TypeError: _API.default is not a constructor
但是..。好像我的默认设置好了?
我的Jest设置如下:
"jest": {
"setupFiles": [
"
我是使用UseHistory钩子在反应路由器v5.1.2与类型记录?在运行单元测试时,我遇到了问题。
TypeError:无法读取未定义的属性“历史记录”。
import { mount } from 'enzyme';
import React from 'react';
import {Action} from 'history';
import * as router from 'react-router';
import { QuestionContainer } from './QuestionsContai
是否可以访问简单提供程序类中的配置工厂生成的嵌套配置?
像这样:
/*Can't use ConfigService because there is no way of injecting it seemingly*/
export const databaseProviders = [
{
provide: 'SEQUELIZE',
useFactory: async () => {
const sequelize = new Sequelize({
host: ConfigService.get<stri
我的项目中有两个数据库连接,因此我不得不按照文档的建议命名其中的一个。使用这个命名连接的模块无法解决我的实体的存储库的依赖,我也找不到原因。
我认为这与连接的“命名”有关,因为当我命名主连接时,其他存储库也有同样的问题。
感谢你的帮助!
错误:
Nest can't resolve dependencies of the DataFactService (?). Please make sure that the argument DataFactRepository at index [0] is available in the DataFactModule context.
P
我试图在我的react原生项目中设置Jest,但它在bugsnag-react-native上运行得并不好。 在我当前的测试配置中,我看到了与bugsnag的leaveBreadcrumb函数相关的错误,如下所示: FAIL app/__tests__/NetworkReducer.test.js
● Test suite failed to run
TypeError: Cannot read property 'default' of undefined
at Object.<anonymous> (app/__tests__/
我试图使用jest来模拟导入的函数,但是我得到了这个错误TypeError: Assignment to constant variable.或TypeError: Cannot assign to read only property 'sum' of object '[object Module]',我希望我得到了在这个测试中模拟的返回值。
尝试1
import { jest } from '@jest/globals'
import * as util from "./util.js"
it("TypeError:
在为Svelte组件编写Jest测试时,当组件使用es6导入语法导入库时,我得到了一个TypeError: Select is not a constructor错误。
TestSelect.js:
<script>
import Select from 'svelte-select';
let items = [
{value: 'chocolate', label: 'Chocolate'},
{value: 'pizza', label: 'Pizza'},
{v