小编tns*_*day的帖子

使用 Jest 测试特定文件

在我的项目文件夹中,我有很多子文件夹,每个子文件夹中都有 js 代码和 test.js 文件。我希望能够测试特定文件。例如,假设我们的项目文件夹中有“fib”文件夹:

\n
C:.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80exercises\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80fib\n            fib-test.js\n            index.js\n
Run Code Online (Sandbox Code Playgroud)\n

现在,从练习文件夹中执行 jest 命令:

\n
jest fib\\fib-test.js\n
Run Code Online (Sandbox Code Playgroud)\n

我得到:

\n
No tests found, exiting with code 1\nRun with `--passWithNoTests` to exit with code 0\nIn C:\\exercises\n  62 files checked.\n  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 26 matches\n  testPathIgnorePatterns: \\\\node_modules\\\\ - 62 matches\n  testRegex:  - 0 matches\nPattern: fib\\fib-test.js - 0 matches\n
Run Code Online (Sandbox Code Playgroud)\n

如果我只是开玩笑,我将运行所有测试。如果我将 fib 文件夹移出练习文件夹,它会按预期工作。这是所有文件的代码:

\n

索引.js:

\n
function fib(n) {}\n\nmodule.exports = fib;\n
Run Code Online (Sandbox Code Playgroud)\n

测试.js:

\n
const fib = require(\'./index\');\n\ntest(\'Fib function is defined\', () …
Run Code Online (Sandbox Code Playgroud)

javascript testing jestjs

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

Yii2 无法实例化组件或类“db”

我使用 Yii2 控制台应用程序来运行迁移。这是一个非常基本的应用程序,它是这样的(项目的 / 文件夹中的 yii.php):

<?php

    require __DIR__ . '/vendor/autoload.php';
    require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
    $config = require __DIR__ . '/config/console.php';

    (new yii\console\Application($config))->run();

?>
Run Code Online (Sandbox Code Playgroud)

所以当我跑

php yii.php
Run Code Online (Sandbox Code Playgroud)

一切都很好,但是当我跑步时

php yii.php migrate/create create_user_table
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息:

Error: Failed to instantiate component or class "db".
Run Code Online (Sandbox Code Playgroud)

我的 Yii 是 v2.0.15.1

UPD 19:32 30/12/2018 当我将 db 配置添加到 config/console.php 时,如下所示:

    return [
    'id' => 'school-console',
    'basePath' => dirname(__DIR__),
    'db' => [
              'class' => 'yii\db\Connection',
              'dsn' => 'mysql:host=localhost;dbname=school',
              'username' => 'root',
              'password' => 'Taras1love',
              'charset' => 'utf8',
    ] …
Run Code Online (Sandbox Code Playgroud)

migration yii2

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

Vue.js - 在 Vue 组件中嵌入 Swagger UI?

我的 Vue 组件中有一个表单,用于上传 api 文件。现在我想像这样渲染文件的内容: swagger-ui 示例

我导入了 swagger 客户端库: https: //github.com/swagger-api/swagger-ui。现在,这里

是如何在静态页面中执行此操作的示例。但我需要在 Vue 组件(特别是 Quasar)内执行此操作,所以我这样做:

在我的注册组件文件中注册 swagger-ui:

<link rel="stylesheet" type="text/css" href="swagger-ui.css">
Run Code Online (Sandbox Code Playgroud)

现在它可以作为:

this.swaggerUI({})
Run Code Online (Sandbox Code Playgroud)

我的组件中的任何地方。在我的组件中,我在模板中有一个 div 来渲染 api 文件:

<template>
    <q-form>here lies q-file element, submit button and other stuff</q-form>
    <div id="swagger-ui"></div>
</template>
Run Code Online (Sandbox Code Playgroud)

在提到的问题中,他有这样的内容:

<script>
  window.onload = function() {
    const ui = SwaggerUIBundle({
      url: "https://yourserver.com/path/to/swagger.json",
      dom_id: '#swagger-ui',
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
      ]
    })

    window.ui = ui
  }
</script>
Run Code Online (Sandbox Code Playgroud)

区别如下:首先,没有 window.onload,我必须在提交按钮上呈现它。然后,我处理存储在我的模型中的上传文件,因此这里没有 URL。现在,我不知道如何使其与本地存储的文件一起使用,当我尝试使用远程 url 时,它给了我:

vue.esm.js?a026:628 [Vue warn]: Error in v-on handler: "Invariant …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui vue.js

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

创建React应用程序时如何解决npm ERR_SOCKET_TIMEOUT错误?

我使用 npx create-react-app 来引导我的项目。安装过程崩溃并显示:

npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/@babel%2fhelper-compilation-targets: Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help …
Run Code Online (Sandbox Code Playgroud)

sockets npm create-react-app

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