小编Nee*_*raj的帖子

Jest&Enzyme-SyntaxError:意外的令牌导入

使用Jest&Enzyme为我的React App编写测试使我深受打击,因为我无法与Jest一起设置Enzyme。

下面是我在测试文件中使用此行时遇到的错误 import React from 'react';

FAIL  src\App.test.js
  ? Test suite failed to run

    D:\experiements\react\my-app\src\App.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.049s
Ran all test suites.
npm ERR! Test failed.  See above for more details.
Run Code Online (Sandbox Code Playgroud)

package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap-daterangepicker": "^2.1.30",
    "history": "^4.7.2",
    "jquery": "^3.3.1",
    "moment": "^2.21.0",
    "npm": "^5.7.1", …
Run Code Online (Sandbox Code Playgroud)

installation reactjs jestjs enzyme

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

[Angular 7+]:如何在另一个服务规范中对服务进行单元测试?

我有这两个服务文件,其中一个包含在另一个中。

应用程序服务.ts

    import { Injectable } from '@angular/core';
    import { HttpClient, HttpHeaders } from '@angular/common/http';

    import { throwError, Observable } from 'rxjs';

    import { catchError, map } from 'rxjs/operators';

    import { Router } from '@angular/router';

    import { environment } from '../../environments/environment';

    import { AuthService } from '../_services/auth.service';

    @Injectable({
        providedIn: 'root'
    })
    export class AppService {

        protected _apiURL = environment.apiURL;
        // Define URLs here
        _overviewURL: string;
        _deleteUserUrl: string;

        constructor(private http: HttpClient,
                    private _router: Router,
                    private _authService: AuthService) {
            this.setApiUrl();
        }

        /* …
Run Code Online (Sandbox Code Playgroud)

testing service injectable angular

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

NestJS:在异常过滤器之前执行拦截器

我需要对某些 ​​API 调用进行事件跟踪(基于处理程序名称),它基本上是一个记录活动的函数。

目前我有一个拦截器可以执行此事件跟踪并且工作正常。

但问题是,每当出现错误时,我都会使用全局异常过滤器捕获它,并且这会立即返回响应,而无需输入拦截器和我的事件跟踪代码(我需要类名称、处理程序名称和返回的数据(如果可用))。

这是我的设置

应用程序模块.ts

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';

import { AuthModule } from './auth/auth.module';
import { MembersModule } from './members/members.module';

import { DatabaseConfigService } from './_database/database-config.service';
import { EventTrackerService } from './event-tracker/event-tracker.service';

import { LoggingInterceptor } from './_interceptors/logging.interceptor';
import { EventsTrackerInterceptor } from './_interceptors/events-tracker.interceptor';

import { AllExceptionsFilter } from './_filters/all-exception.filter';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true, …
Run Code Online (Sandbox Code Playgroud)

typescript nestjs

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

ASP.NET的计划任务

如何在Windows的计划任务中执行asp.NET代码?

asp.net scheduled-tasks

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

Javascript - 动态添加输入字段

我有一个代码来动态地在js中添加输入字段.但问题是如果我添加3个或更多字段然后浏览文件(如果输入字段是文件),则所选字段的值将消失.任何人都可以帮忙

继承我的代码

提前致谢.:)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Husay :: http://www.communitxt.net */

var arrInput = new Array(0);
 var arrInputValue = new Array(0);
fields = 1;
maxInput = 4;
function addInput() {
 //arrInput.push(createInput(arrInput.length));
 if(fields <= maxInput){
     fields +=1;
     arrInput.push(arrInput.length);
     //arrInputValue.push(arrInputValue.length);
     arrInputValue.push("");
     display();
 }
}

function display() { …
Run Code Online (Sandbox Code Playgroud)

javascript dynamic

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

Redux-form:如何在模式弹出时从 API 调用加载值(编辑模式)到表单?

我对 React 和 Redux-Form 还很陌生,目前我需要一些帮助。

基本上我有列表页面和他们的编辑按钮。单击编辑时,我会显示一个带有字段的模式弹出窗口,并执行 API 调用以获取相应的列表数据。

您能否让我知道如何使用从 API 调用接收到的数据预先填充模态弹出窗口中的字段?

非常感谢带有代码示例的演示(就像我说我对 React & Redux & Redux-form 很陌生)。:(

提前致谢!

html javascript reactjs redux redux-form

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