小编Alp*_*a60的帖子

Jest & TypeScript:VS Code 找不到名字

我正在将 Jest 与 TypeScript 一起使用。尽管我的代码可以工作并且我可以构建我的项目,但 Visual Studio Code 会为所有 Jest 方法(describe()test()...)抛出该错误:

Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.ts(2582)
Run Code Online (Sandbox Code Playgroud)

我有srctests分开的目录。我遵循了在 Internet 上找到的配置,但它没有改变任何东西,我错过了什么?到目前为止唯一的方法是将我的tests文件夹包含在 中的include设置中tsconfig,这很糟糕,因为它内置在dist目录中。

安装的开发依赖项: jest ts-jest @types/jest

tsconfig.json

{
  "compilerOptions": {
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowJs": true,
    "jsx": "react",
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"], …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig jestjs visual-studio-code ts-jest

7
推荐指数
1
解决办法
2205
查看次数

Docker 环境中的 Ethers.js JsonRpcProvider Geth 节点

我正在尝试将 Ethers.js 连接到在 Docker 容器中运行的本地 Ehereum 节点 (Geth)。在客户端,我以这种方式创建提供程序:new ethers.providers.JsonRpcProvider('http://geth:8545')geth是节点容器主机名,并且两个容器位于同一网络上:我可以从客户端容器内 ping Geth 节点。当我开始从客户端请求节点时,出现错误"noNetwork"

当我在没有 Docker 的情况下运行客户端,通过 请求节点容器时http://localhost:8545,它工作正常。

怎么了?

  • Geth 节点的 Docker-compose 文件:
version: "3.5"

services:
  geth:
    container_name: geth
    image: ethereum/client-go:latest
    volumes:
      - /etc/geth:/root/.ethereum:rw
    ports:
      - "8545:8545"
      - "30303:30303"
    networks:
      - ethereum
    entrypoint: "geth --nousb --http --http.corsdomain '*' --http.addr 0.0.0.0 --http.api personal,eth,net,web3 --syncmode light"

networks:
  ethereum:
    name: ethereum-net
Run Code Online (Sandbox Code Playgroud)
  • 客户端的 Docker-compose 文件:
version: "3.5"

services:
  eth-server:
    container_name: eth_server_dev
    build: packages/eth-server/.
    environment:
      - NODE_ENV=development
      - NODE_PORT=3002 …
Run Code Online (Sandbox Code Playgroud)

docker blockchain docker-compose ethereum geth

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

Ruby on Rails API:计算属性模式最佳实践

当我需要需要调用数据库的计算属性时,我想知道最佳实践。

如果我有一个Parent有 many Child,我将如何渲染一个children_count属性,ParentController#index因为我不想渲染孩子,只是计数?最好的方法是什么?

谢谢!

模型:

class Parent < ApplicationRecord
  has_many :children

  def children_count
    children.count # Wouldn't it ask the database when I call this method?
  end
end
Run Code Online (Sandbox Code Playgroud)

控制器:

class ParentsController < ApplicationController
  def index
    parents = Parent.all

    render json: parents, only: %i[attr1, attr2] # How do I pass children_count?
  end
end
Run Code Online (Sandbox Code Playgroud)

design-patterns ruby-on-rails ruby-on-rails-6

3
推荐指数
1
解决办法
59
查看次数