小编use*_*909的帖子

配置 jest moduleNameMapper 不起作用

我想对反应组件应用玩笑测试,但收到一条错误消息:

Jest 遇到意外令牌

当我尝试:

import moment from 'moment';
import './style.css';   //<----here
Run Code Online (Sandbox Code Playgroud)

我尝试模拟 css 文件和图像对象并更改配置:

// package.json
{
"jest": {
"moduleNameMapper": {
  "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
  "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
}
}
}
Run Code Online (Sandbox Code Playgroud)

我的 styleMock.js 是:

module.exports = {};
Run Code Online (Sandbox Code Playgroud)

我的 fileMock.js 是:

module.exports = 'test-file-stub';
Run Code Online (Sandbox Code Playgroud)

但我仍然收到错误:

Jest 遇到意外令牌

并且错误与之前的位置相同。

我的笑话是最新版本“24.8.0”。

有人知道为什么吗?

javascript mocking reactjs jestjs

7
推荐指数
0
解决办法
4038
查看次数

django-rest-framework:__ init __()只取1个参数(给定2个)

我的错误类似于django错误:__ init __()只需要1个参数(给定2个),但由于没有正确的答案,我现在无法找到解决方法.所以,我再问一次.

在views.py中我写道:

class JSONResponse(HttpResponse):
    """
    An HttpResponse that renders its content into JSON.
    """
    def __init__(self, data, **kwargs):
        content = JSONRenderer().render(data)
        kwargs['content_type'] = 'application/json'
        super(JSONResponse, self).__init__(content, **kwargs)

class SnippetListView(APIView):
    queryset = Snippet.objects.all()

    def get(self, request, format=None):
        users = self.queryset
        serializer = SnippetSerializer(users, many=True)
        return Response(serializer.data)

    def post(self, request, format=None):     
        serializer = SnippetSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
       else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Run Code Online (Sandbox Code Playgroud)

在urls.py中我写道:

from django.conf.urls import patterns, url
from rest_framework.urlpatterns import format_suffix_patterns
from snippets.views import * …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

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

scala将来的错误"不要直接调用`Awaitable`方法,使用`Await`对象."

我的特质方法是:

userService{
  def link(current: U, to:User): Future[U]
  def findUserByEmail(email:String):Future[Option[User]]
}
Run Code Online (Sandbox Code Playgroud)

当我执行时我使用:

for(link(currentUser, userService.findUserByEmail(email).result(Duration(1000, MILLISECONDS)).get)){
...
}
Run Code Online (Sandbox Code Playgroud)

而错误是:

[error] G:\testprojects\mifun\modules\app\controllers\
ProviderController.scala:130: Don't call `Awaitable` methods directly, use the `
Await` object.
Run Code Online (Sandbox Code Playgroud)

我不知道为什么这里必须使用await对象而不是等待方法,以及如何正确地更改它.

asynchronous scala

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

如何手动映射字符串到PostgreSQL的文本,而不是仅仅为varchar(254)?

我使用slick2 + postgresql 9.3 + playframework 2

我的数据模型是:

class Page(tag:Tag) extends Table[(Long,Long, String,String,String, Option[Long], Option[Long])](tag, "Page"){
  def id=column[Long]("ID", O.PrimaryKey)
  def subId=column[Long]("subject")
  def title=column[String]("Title", O.NotNull)
  def describe=column[String]("Describe")
  def profile=column[String]("Profile")
  def icon=column[Long]("icon")
  def resId=column[Long]("Picture")
  def * = (id, subId,title, describe, profile,icon.?, resId.?)
  def page_sub=foreignKey("PA_SU_FK", subId, subject)(_.id)
  def page_res=foreignKey("PA_RE_FK", resId, resource)(_.id)

}
Run Code Online (Sandbox Code Playgroud)

问题是列描述是字符串和将映射在数据库的varchar(254).但实际上,这个专栏可能很长,我的意思是它可能有1000-3000个字符.如何手动将其映射到Datamodel中的文本?

postgresql scala slick slick-2.0

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

如何在 JavaScript 中克隆迭代器?

在 ES6 中,是否有可能克隆迭代器状态?

var ma=[1,2,3,4];
var it=ma[Symbol.iterator]();
it.next();
Run Code Online (Sandbox Code Playgroud)

如果我想记住这里它指出我应该在javascritp中做什么?

里面记着什么?自从

JSON.stringify(it) //it would just return {}
Run Code Online (Sandbox Code Playgroud)

javascript iterator ecmascript-6

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

aws lambda 上的无服务器收到内部服务器错误的 502 错误

我尝试将无服务器与 aws lambda 服务结合使用。

我的 serverless.yml 是:

service: webpack-4-example

# Add the serverless-webpack plugin
plugins:
  - serverless-webpack
  - serverless-offline

provider:
  name: aws
  runtime: nodejs8.10
  region: us-west-2
  stage: dev

package:
  individually: true

functions:
  first:
    handler: handlers/first.hello
    events:
      - http:
          method: get
          path: /first
  second:
    handler: handlers/second.hello
    events:
      - http:
          method: get
          path: /second

custom:
  webpack:
    webpackConfig: 'webpack.config.js'
    includModules: true
    packager: 'npm'
Run Code Online (Sandbox Code Playgroud)

我使用 serverless-webpack 和 serverless-offline 插件。

我只是为 first.js 编写了简单的无服务器

export const hello = async (event, context) => {
const rep = …
Run Code Online (Sandbox Code Playgroud)

node.js aws-lambda bad-gateway serverless

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

对于打字稿,当前未启用“decorators-legacy”的错误,我设置了experimentalDecorators 和emitDecoratorMetadata 的事件为true

我将 typeorm 与 next.js 和 typescript 一起使用,我的 tsconfig.json 是:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext",
      "es5",
      "es6"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "jsx": "preserve"
  },
   include: ...

}
Run Code Online (Sandbox Code Playgroud)

我设置experimentalDecorator 为true。我的打字稿是 3.9.7,我的打字稿是 0.2.25。编译错误是:

error - ./db/entity/User.ts:7:1
Syntax error: Support for the experimental syntax 'decorators-legacy' isn't currently enabled:

   5 |
   6 |
>  7 | @Entity()
     | ^ …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig next.js typescript-decorator

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

光滑的过滤器或不再支持逻辑操作的地方?

我使用slick 2.0.2并且我只想做一个简单的过滤器或使用where子语句,我只想在过滤器中执行"and","or"和"not"之类的逻辑操作:

val subjectdata = TableQuery[SubjectTable]
...
subjectdata.where(i=>(i.id===id && i.userId===rs.user.get.identityId.userId)).list()
Run Code Online (Sandbox Code Playgroud)

并得到错误:

[error] G:\testprojects\slickplay\app\controllers\ShopController.scala:89: Cannot perform option-mapped operation
[error]       with type: (Long, String) => R
[error]   for base type: (Long, Long) => Boolean
[error]     subjectdata.where(i=>(i.id===id && i.userId===rs.user.get.identityId
.userId)).list()
[error]
                           ^
Run Code Online (Sandbox Code Playgroud)

在光滑的1.0.1我可以这样做:

val results = Query(TableClass)
.filter(r => r.isNull || r.expires > new Timestamp(DateTime.now().getMillis()))
.list
Run Code Online (Sandbox Code Playgroud)

我想在Slick2中的TableQuery上做类似的事情.怎么做?

scala logical-operators slick slick-2.0

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

使用 playframework 执行 nohup 命令会出现错误的文件描述符错误

我使用 playframework2.2 和 sbt 0.13.1,我可以运行 sbt 并在命令行上启动服务器

开始

工作正常。但是当我跑步时:

nohup sbt 启动

它运行了一段时间,然后停止并出现日志错误:

(Starting server. Type Ctrl+D to exit logs, the server will remain in background)  java.io.IOException: Bad file descriptor
at java.io.FileInputStream.read0(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:210)
at jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:248)
at jline.internal.InputStreamReader.read(InputStreamReader.java:261)
at jline.internal.InputStreamReader.read(InputStreamReader.java:198)
at jline.console.ConsoleReader.readCharacter(ConsoleReader.java:2038)
at  play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.play$PlayConsoleInteractionMode$$anonfun$$waitEOF$1(PlayInteractionMode.scala:36)
at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1$$anonfun$apply$1.apply$mcV$sp(PlayInteractionMode.scala:45)
at play.PlayConsoleInteractionMode$$anonfun$doWithoutEcho$1.apply(PlayInteractionMode.scala:52)
at play.PlayConsoleInteractionMode$$anonfun$doWithoutEcho$1.apply(PlayInteractionMode.scala:49)
at play.PlayConsoleInteractionMode$.withConsoleReader(PlayInteractionMode.scala:31)
at play.PlayConsoleInteractionMode$.doWithoutEcho(PlayInteractionMode.scala:49)
at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.apply(PlayInteractionMode.scala:45)
at play.PlayConsoleInteractionMode$$anonfun$waitForKey$1.apply(PlayInteractionMode.scala:34)
at play.PlayConsoleInteractionMode$.withConsoleReader(PlayInteractionMode.scala:31)
at play.PlayConsoleInteractionMode$.waitForKey(PlayInteractionMode.scala:34)
at play.PlayConsoleInteractionMode$.waitForCancel(PlayInteractionMode.scala:55)
at play.PlayRun$$anonfun$24$$anonfun$apply$9.apply(PlayRun.scala:373)
at play.PlayRun$$anonfun$24$$anonfun$apply$9.apply(PlayRun.scala:352)
at scala.util.Either$RightProjection.map(Either.scala:536)
at play.PlayRun$$anonfun$24.apply(PlayRun.scala:352)
at play.PlayRun$$anonfun$24.apply(PlayRun.scala:334)
at sbt.Command$$anonfun$sbt$Command$$apply1$1$$anonfun$apply$6.apply(Command.scala:72)
at sbt.Command$.process(Command.scala:95)
at …
Run Code Online (Sandbox Code Playgroud)

linux scala nohup playframework playframework-2.2

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

如何在适用于 Linux 的 Windows 子系统上的 docker 中使用 -v 卷参数

我的 windows 10 版本是 1803

我安装 docker Fellow 的链接:

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawless

我尝试使用 docker 的 -v 如下:

docker run -it -v ~/.aws:root/.aws/ ubuntu
Run Code Online (Sandbox Code Playgroud)

我也尝试使用:

docker run -it -v $(realpath ~/.aws):/root/.aws ubuntu
Run Code Online (Sandbox Code Playgroud)

但我发现我想映射到 docker 系统的卷不存在。

当我做:

ls /root/.aws

总是空的,如何在Windows Subsystem for linux上映射数据卷?

volume docker windows-subsystem-for-linux

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