小编ysf*_*ran的帖子

如何读取测试中的笑话配置值?

jest允许您使用CLI 选项或文件设置全局配置值package.jsonjest.config.js

您可以在测试中设置一些配置值,例如

jest.setTimeout(10000000)
Run Code Online (Sandbox Code Playgroud)

但我找不到读取配置值的方法,例如

const initialTimeout = jest.testTimeout // this is undefined
jest.setTimeout(10000000)
// do something that takes unusually long time
jest.setTimeout(initialTimeout)
Run Code Online (Sandbox Code Playgroud)

那么如何读取测试中当前设置的全局配置值呢?

javascript jestjs

13
推荐指数
1
解决办法
1672
查看次数

当包具有公共依赖项时,私有包的 npm 安装失败

可以说我有一个私人NPM库,内举办JFrog artifactory的https://my-domain.com/artifactory/api/npm/my-repo。在这个存储库中,我发布了一个 npm package: my-package,它构建得很好。my-package依赖(或更多)公共 npm包,例如lodash.

但是,当我创建一个新项目并尝试安装时my-package,出现以下错误:

$ npm install my-package --registry https://my-domain.com/artifactory/api/npm/my-repo
npm ERR! code E404
npm ERR! 404 Not Found - GET https://my-domain.com/artifactory/api/npm/my-repo/lodash - not_found
npm ERR! 404
npm ERR! 404  'lodash^4.17.11' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'my-package' …
Run Code Online (Sandbox Code Playgroud)

npm npm-install npm-registry

6
推荐指数
1
解决办法
5039
查看次数

是否可以选择严格传播对象?

我想知道是否有编译器选项或类似的东西可以使传播对象严格。

请参阅以下示例以了解我的意思:

interface Foo {
  a: string;
}

interface Bar {
  a: string;
  b: number;
}

const barObject: Bar = { a: "a string", b: 1 };

// should give a warning because Bar has more properties (here b) than Foo
const fooObject: Foo = { ...barObject };

// actually prints 1
console.log((fooObject as any).b); 
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

typescript

6
推荐指数
1
解决办法
588
查看次数

如何使 IntersectionObserver 与变换翻译动画一起使用?

我想为具有以下属性的元素创建动画:

  • 当元素进入视口时它会对其进行动画处理
  • 如果元素离开视口然后再次进入它应该再次动画
  • 根据滚动方向/相交侧(从顶部或底部),动画应该不同

为此,我使用了一个IntersectionObserver并且我接近了预期的结果。
我面临的唯一问题是,当我在动画期间沿滚动方向(在本例中)平移元素时transform: translateY。这将导致IntersectionObserver触发多次甚至无限次。

在此输入图像描述

function isIntersectingFromTop(entry){
  return entry.boundingClientRect.bottom != entry.intersectionRect.bottom;
} 

function isIntersectingFromBottom(entry){
  return entry.boundingClientRect.top != entry.intersectionRect.top;
}

var count = 0;

function incrementCounter(entry){
  document.querySelector(".counter").textContent += "intersectionRation (" + count + "): " + entry.intersectionRatio + "\n";
  count++;
}

let observer = new IntersectionObserver(
function (entries, observer) { 
  entries.forEach(function(entry){
    incrementCounter(entry)
    if (entry.isIntersecting) {
       if(isIntersectingFromTop(entry)){
         entry.target.classList.add("animated--up-in");
       } else if(isIntersectingFromBottom(entry)) {
         entry.target.classList.add("animated--down-in")
       }
    } else { 
      /** element is …
Run Code Online (Sandbox Code Playgroud)

html javascript css intersection-observer

6
推荐指数
1
解决办法
2765
查看次数

CMake:如何指定ctest在其中查找可执行文件的目录?

我想将ctest集成到c ++ / c项目中。我用谷歌测试写单元测试。

我的CMakeLists.txt的相关部分如下所示:

...
####### CREATING EXE #######
add_executable(test_exe main.cpp test.cpp)
target_link_libraries(test_exe GTest::GTest GTest::Main)
set_target_properties (test_exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${UNIT_TEST_BIN_OUTPUT_DIR})
add_test(test_exe test_exe)
Run Code Online (Sandbox Code Playgroud)

如您所见,我指定了可执行文件的输出目录(UNIT_TEST_BIN_OUTPUT_DIR)。

当我使用终端时,可执行文件可以正常工作:

cd <UNIT_TEST_BIN_OUTPUT_DIR>
./test_exe
Run Code Online (Sandbox Code Playgroud)

我想使用ctest执行测试。因此,我转到了cmake生成的“ ctest文件夹”。在这里,我想使用ctest执行cmake中“ add_test”添加的所有测试。

user@user:~/<dir to cmake>/cmake/unit_tests$ ctest
Test project /<dir to cmake>/cmake/unit_tests
    Start 1: test_exe
Could not find executable test_exe
Looked in the following places:
test_exe
test_exe
Release/test_exe
Release/test_exe
Debug/test_exe
Debug/test_exe
MinSizeRel/test_exe
MinSizeRel/test_exe
RelWithDebInfo/test_exe
RelWithDebInfo/test_exe
Deployment/test_exe
Deployment/test_exe
Development/test_exe
Development/test_exe
Unable to find executable: test_exe
1/1 Test #1: test_exe ......***Not Run   0.00 sec …
Run Code Online (Sandbox Code Playgroud)

c++ cmake googletest ctest

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

v16.6.0或更高版本在提供上下文的组件中使用子级时,Context API无法正常工作

我通过声明public static contextType消耗上下文的组件内部来使用react的新上下文API(v16.6.0或更高版本).只要声明Provider它的组件不直接使用消耗其render()方法中的上下文的组件,这就可以正常工作.

例:

ParentWithContext

这是创建和提供上下文的组件.

export const SomeContext = React.createContext({
  someValue: false
});

export default class ParentWithContext extends Component {
  public render(){
    const contextValue = {someValue: true};
    return (
      <SomeContext.Provider value={contextValue}>
        <ChildOne />
        {this.props.children}
      </SomeContext.Provider>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

请注意,此组件ChildOne在其render()方法中使用组件(右下方).

ChildOneChildTwo

这两个组件只是消耗上面的上下文并显示它.

export default class ChildOne extends Component {
  public static contextType = SomeContext;
  public render(){
    return (
      <div>
        {`Context of ChildOne: ${this.context.someValue}`}
      </div>
    );
  }
}

export …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs tsx react-context

5
推荐指数
1
解决办法
337
查看次数

npm install 不考虑 package-lock.json 中的注册表/解析路径

从私有注册表安装软件包非常简单:

npm install my-package --registry https://<private-registry-url>
Run Code Online (Sandbox Code Playgroud)

这将添加一个条目到package-lock.json

"my-package": {
      "version": "1.0.0",
      "resolved": "https://<private-registry-url>/<some_path>/my-package-1.0.0.tgz",
      "integrity": "sha1-Pjs/y9sEp49/OC8+8eEZFdwT3BQ="
    },
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,一切都符合预期。

现在的问题是,当您想使用npm install. 这将失败并出现以下错误:

npm install my-package --registry https://<private-registry-url>
Run Code Online (Sandbox Code Playgroud)

所以它试图my-package从公共 npm 注册表 ( https://registry.npmjs.org/my-package) 中获取,但当然失败了,因为my-package它位于私有注册表中。

现在,这真的伤了我的理解package-lock.json..不应该NPM照照package-lock.json,看看那里的包是前解决?相反,它只是假设它必须在公共注册表中。

另一个有趣的事情是,一旦您--registry再次手动安装带有标志的软件包,它就会起作用:

npm install my-package --registry https://<private-registry-url> && npm i
Run Code Online (Sandbox Code Playgroud)

之后它每次都会工作,直到您升级版本my-package或切换设备。

我也尝试过npm ci命令但没有成功(同样的错误)。

那么如何从私有注册表正确安装软件包,以便可以使用npm install?

npm npm-install package-lock.json

5
推荐指数
0
解决办法
1013
查看次数

是否可以在接口上进行“内部联接”

比方说,我们有两个接口FirstSecond

interface First {
  a: string;
  b: number;
}

interface Second {
  b: number;
  c: Date;
}
Run Code Online (Sandbox Code Playgroud)

使用相交可以合并两个接口:

type FirstSecond = First & Second // {a: string, b: number, c: Date}
Run Code Online (Sandbox Code Playgroud)

但是可以进行内部连接,因此结果接口包含在两个接口中声明的属性:

type FirstSecond = First /*inner join here*/ Second // {b: number}
Run Code Online (Sandbox Code Playgroud)

这对于泛型类型尤其有用。

typescript typescript-generics

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

为 .tsx/.ts 文件中的 css 类名禁用智能感知

每当我.在对象之后输入 a 时,自动完成下拉列表都会包含许多不必要的 css 类名作为选项:

在此处输入图片说明

是否可以忽略 ts/tsx 智能感知的 css 文件,所以我只能得到相关选项?

VS代码版本: 1.37.1

intellisense visual-studio-code

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

在 testRunner 设置为 jest-circus 的情况下访问 jasmine 导致:ReferenceError: jasmine is not defined

默认情况下jest,您可以简单地jasmine全局访问。但是一旦你切换testRunnerjest-circus,jasmine是未定义的。以下是一个最小的、可重现的示例:

babel.config.js

module.exports = {
  presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
Run Code Online (Sandbox Code Playgroud)

茉莉花规范.js

it("check jasmine", () => {
  console.log(jasmine);
});
Run Code Online (Sandbox Code Playgroud)

开玩笑的配置文件

module.exports = {
  rootDir: ".",
  testRunner: "jest-circus/runner",
};
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "test-jest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.12.10",
    "@babel/preset-env": "^7.12.11",
    "babel-jest": "^26.6.3",
    "jest": "^26.6.3",
    "jest-circus": "^26.6.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

运行此测试将导致以下输出:

$ npm test

> …
Run Code Online (Sandbox Code Playgroud)

javascript node.js jasmine jestjs jest-circus

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