小编Jas*_* FB的帖子

使用 domjs 时无法使 refs 工作,经 React 测试库测试

这是一个关于在规范中使用 React refs 的问题。具体来说,我在浏览器中看到的行为与在测试中运行时看到的行为不同。

// app_container.test.js

import React from 'react'
import ReactDOM from 'react-dom'
import AppContainer from "./app_container"
import { render, fireEvent, waitForElement, cleanup, wait } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import axiosMock from 'axios'

import { useAsync } from "react-use"

afterEach(cleanup);

test("renders", () => {
  const { getByTestId } = render(<AppContainer />);
  expect(getByTestId("app-container")).toHaveClass("app-container");

});


test("when mounted, it loads the rings", async () => {
  jest.setTimeout(15000);

  const { getByTestId } = render(<AppContainer />);

  const container = getByTestId('app-container')

  await wait(() => expect(getByText("Abc")).toBeInTheDocument()); …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs react-testing-library react-ref

6
推荐指数
0
解决办法
1123
查看次数

ld:在 macOS Big Sur 11.4 上为 mysql2 gem Ruby 捆绑安装时找不到 -lzstd 的库

在运行 bundle install 时

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)

Rails 应用程序 6.1.3

捆绑器版本 2.2.19

macOS 大苏尔 11.4

在 Gemfile 中

ruby '2.6.6'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
gem 'mysql2'
Run Code Online (Sandbox Code Playgroud)

在 Gemfile.lock mysql 是 0.5.3

当我运行bundle install它时,它会以正常方式崩溃:

在此处输入图片说明

检查输出中较早出现的构建错误,构建错误似乎是:(完整结果如下)

 ld: library not found for -lzstd
Run Code Online (Sandbox Code Playgroud)

来自的完整结果bundle install

jason@MacBook-Air  % bundle install    
Fetching gem metadata from https://rubygems.org/
Fetching gem …
Run Code Online (Sandbox Code Playgroud)

ruby mysql bundler mysql2 macos-big-sur

6
推荐指数
4
解决办法
1828
查看次数

如何在 Render 上对基于 Rails 的应用程序进行运行状况检查?

渲染需要 /health 端点,但是当我在应用程序中创建它并首次部署时,我无法部署,因为如果没有先运行迁移,应用程序就无法启动。

看来 Render.com 运行状况检查需要运行状况端点即使在迁移运行之前也能响应正常。我怎样才能做到这一点?

rack ruby-on-rails render.com

5
推荐指数
2
解决办法
5482
查看次数

React 测试库 - 测试时如何查看 DOM 的当前状态

我正在学习React测试库(多年其他语言的TDD经验)

\n

React 测试库的文档说,当getByText失败时,它“但是会打印正在测试的 DOM 的状态”:

\n

https://testing-library.com/docs/dom-testing-library/api-debugging/

\n

在此输入图像描述

\n

然而,在当前的 RTL 中,这种情况不会发生在我身上。

\n

相反,我得到这个:

\n
  \xe2\x97\x8f loads and displays greeting\n\n    TestingLibraryElementError: Unable to find an element with the text: the current weather is: overcast clouds. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.\n\n    Ignored nodes: comments, <script />, <style />\n    <h1\n      data-testid="currentWeatherOutput"\n    />\n\n      27 | …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-testing-library react-testing

5
推荐指数
2
解决办法
2万
查看次数

从 ruby​​ 2.7 升级到 3.0 时遇到问题 - 错误:使用未声明的标识符“RUBY_FUNCTION_NAME_STRING”

我已经在努力尝试升级 Rails 3.0 大约一周了。

我不完全确定问题是什么,但我认为这可能是因为我同时拥有 rvm 和 rbenv。

我在这里遵循了 gorails 的升级教程:https ://gorails.com/setup/osx/12-monterey

但每当我跑步时:

$ rbenv install 3.0.3

我收到以下错误:

In file included from compile.c:40:
./vm_callinfo.h:217:16: error: use of undeclared identifier 'RUBY_FUNCTION_NAME_STRING'
    if (debug) rp(ci);
               ^
./internal.h:95:72: note: expanded from macro 'rp'
#define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
Run Code Online (Sandbox Code Playgroud)

这也是我的错误日志的一个例子:

In file included from compile.c:40:
./vm_callinfo.h:217:16: error: use of undeclared identifier 'RUBY_FUNCTION_NAME_STRING'
    if (debug) rp(ci);
               ^
./internal.h:95:72: note: expanded from macro 'rp'
#define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
                                                                       ^
2 errors generated. …
Run Code Online (Sandbox Code Playgroud)

ruby development-environment rbenv ruby-upgrade ruby-3

5
推荐指数
2
解决办法
5167
查看次数

Rails 7:validate_secret_key_base':缺少“生产”环境的“secret_key_base”

导轨7.0.4

使用 MRSK 部署时出现此错误

[linux/arm64 build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile: #23 1.053 Rails 中止!#23 1.053 ArgumentError:缺少secret_key_base“生产”环境,请使用 #23 1.053 /rails/config/environment.rb:5:in `' 设置此字符串bin/rails credentials:edit #23 1.053 任务:TOP => 环境 #23 1.053 (请参阅完整跟踪使用 --trace 运行任务)

我的 Dockerfile 中卡住的行是

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
Run Code Online (Sandbox Code Playgroud)

如果我运行,EDITOR=emacs bin/rails credentials:edit我可以看到secret_base_key加密凭证文件中已经有一组

在我的 Production.rb 文件中,这一行被注释掉:

  # config.require_master_key = true
Run Code Online (Sandbox Code Playgroud)

如果我取消注释上面的行,错误将更改为:

 > [linux/arm64 build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
#22 0.999 Missing encryption key …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mrsk

5
推荐指数
2
解决办法
2406
查看次数

RVM 安装 ruby​​ 2.6.4 失败并出现 makefile 错误:函数“ffi_prep_closure”的隐式声明在 C99 中无效

RVM rvm 1.29.12-next

M1 芯片上的 Mac OS Big Sur

rvm install 2.6.4 失败:

Error running '__rvm_make -j8',
please read /Users/jason/.rvm/log/1626110300_ruby-2.6.4/make.log

There has been an error while running make. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

生成文件错误是:

error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
Run Code Online (Sandbox Code Playgroud)

ruby rvm macos-big-sur

4
推荐指数
1
解决办法
262
查看次数

在 Rails 中使用 Postgres Enum 类型时,在迁移中指定 CREATE TYPE xyz_setting AS ENUM 会破坏 db/schema.rb 文件

这是基于这里的一些 dev.to 文章https://dev.to/diegocasmo/using-postgres-enum-type-in ​​-rails-30mo 和这里https://dev.to/amplifr/postgres-enums-with -rails-4ld0 和同一个人的文章https://medium.com/@diegocasmo/using-postgres-enum-type-in ​​-rails-799db99117ff

如果您遵循上述建议,建议您CREATE TYPE xyz_setting AS ENUM直接在 Postgres 上使用,为您的 Postgres 支持的架构创建 Rails 架构迁移,然后使用它来创建新字段作为 ENUM(postgres 枚举)

不幸的是,这种方法的缺点是会破坏db/schema.rb文件。

我认为问题在于 Rails 核心不支持本机 Postgres 类型。

我可以在 Rails 5.17、5.2.2.4 和 6.0.3 上重现该行为

如果我做...

class AddXyzToUsers < ActiveRecord::Migration[5.2]
  def up
    execute <<-DDL
          CREATE TYPE xyz_setting AS ENUM (
            'apple', 'bananna', 'cherry'
          );
    DDL
    add_column :users, :xyz, :xyz_setting
  end

  def down
    remove_column  :users, :xyz
    execute "DROP type xyz_setting;"
  end
end
Run Code Online (Sandbox Code Playgroud)

那么我的模式文件就混乱了,具体来说,模式用户表没有得到任何输出,取而代之的是这条消息

由于以下标准错误,无法转储表“用户”

列“xyz”的未知类型“xyz_setting”

postgresql enums ruby-on-rails

2
推荐指数
1
解决办法
3720
查看次数

使用本机扩展安装 puma 5.6.2 Gem::Ext::BuildError: ERROR: 无法构建

红宝石3.1.0

Rails 7.0.2.2(包含捆绑和 Postgresql)

运行捆绑安装时,我在 puma 5.6.2 上不断遇到这种奇怪的崩溃。

% bundle install           
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Using rake 13.0.6
Using racc 1.6.0
Using crass 1.0.6
Using minitest 5.15.0
Using builder 3.2.4
Using digest 3.1.0
Using rack 2.2.3
Using io-wait 0.2.1
Using concurrent-ruby 1.1.9
Using websocket-extensions 0.1.5
Using marcel 1.0.2
Using mini_mime 1.1.2
Using bundler 2.3.3
Using timeout 0.2.0
Using nio4r 2.5.8
Using strscan 3.0.1
Using bindex 0.8.1
Using public_suffix 4.0.6
Using thor 1.2.1
Using erubi 1.10.0
Using …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails bundler puma

2
推荐指数
1
解决办法
8710
查看次数

Nock JS 模拟工具产生错误“'instanceof' 的右侧不是对象”

我正在尝试使用这个名为Nock JS的工具

\n

https://www.npmjs.com/package/nock

\n

使用Next JS,使用Cypress测试React演示应用程序

\n

\xe2\x80\xa2 下一个 JS 13.4

\n

\xe2\x80\xa2\xc2\xa0赛普拉斯 12.17.1

\n

\xe2\x80\xa2 反应 18.2

\n

e2e/homepage.cy.js

\n
\n\ndescribe(\'weather app spec\', () => {\n  it(\'can load the current weather\', () => {\n\n\n    const nock = require(\'nock\')\n\n    const scope = nock(\'https://api.openweathermap.org\')\n      .get(\'/data/2.5/weather\')\n      .reply(200, {\n      "coord":  {\n           "lon": -73.9629,\n           "lat": 40.6884\n      },\n      "weather"  :\n        [{"id": 211, "main": "scattered clouds", "description": "scattered clouds", "icon": "11d"}, {\n          "id": 500,\n          "main": "Rain",\n          "description": "scattered clouds",\n …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs nock next.js cypress

2
推荐指数
1
解决办法
160
查看次数