小编Ree*_*ong的帖子

如何使用Jest正确模拟第三方库(如jQuery和语义UI)?

在过去的几周里,我一直在学习React,Babel,Semantic UI和Jest.我没有真正遇到太多问题,我的组件没有在浏览器中呈现,但我在使用Jest编写单元测试时遇到了渲染问题.

SUT如下:

EditUser.jsx

var React = require('react');
var { browserHistory, Link } = require('react-router');
var $ = require('jquery');

import Navigation from '../Common/Navigation';

const apiUrl = process.env.API_URL;
const phoneRegex = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;

var EditUser = React.createClass({
  getInitialState: function() {
    return {
      email: '',
      firstName: '',
      lastName: '',
      phone: '',
      role: ''
    };
  },
  handleSubmit: function(e) {
    e.preventDefault();

    var data = {
      "email": this.state.email,
      "firstName": this.state.firstName,
      "lastName": this.state.lastName,
      "phone": this.state.phone,
      "role": this.state.role
    };

    if($('.ui.form').form('is valid')) {
      $.ajax({
        url: apiUrl + …
Run Code Online (Sandbox Code Playgroud)

jquery reactjs semantic-ui jestjs babeljs

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

有没有办法为VSTS CI npm任务提供环境变量?

基本上,我需要一种方法为我的应用程序注入环境变量,因为我不想将.env文件检入我的仓库.我希望运行类似的东西API_URL=api.example.com npm run build,但看起来你不能在任务命令之前添加前缀.

有没有办法做到这一点,还是有更好的方法为Azure中托管的节点应用程序创建环境变量?

node.js npm azure-devops azure-pipelines

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

如何从 akka Source[ByteString, _] 中提取 Future[String]?

我正在尝试使用 akka 流来流式传输文件,并且遇到了将流的结果提取到 Future[String] 中的小问题:

def streamMigrationFile(source: Source[ByteString, _]): Future[String] = {
  var fileString = ""
  val sink = Sink.foreach[ByteString](byteString => fileString = 
    fileString.concat(byteString.decodeString("US-ASCII")))
  source.runWith(sink)
}
Run Code Online (Sandbox Code Playgroud)

我收到编译错误:

Expression of type Future[Done] does not conform to expected type Future[String]
Run Code Online (Sandbox Code Playgroud)

谁能帮助我理解我做错了什么以及我需要做什么来提取流的结果?

scala akka akka-stream akka-http

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

Java:如何对在方法范围内创建和操作文件的方法进行单元测试?

我正在使用 JUnit 和 JMockit 创建一个单元测试方法,用于测试 CSV 文件的创建和操作。如何拦截正在创建的文件以确保正确创建?

@Test
public void testPersistResultsAsCSV() throws IOException {
    final Long id = new Long(1234l);

    TableRow row = new TableRow();
    row.setValue(317l);
    row.setId(1234l);

    final List<TableRow> rows = new ArrayList<TableRow>();
    rows.add(row);

    final List<TableRow> empty = new ArrayList<TableRow>();

    new Expectations() {
        {
            tableService.findTableRowsById(id, (TableQueryOptions)any);
            result = rows;

            tableService.findTableRowsById(id, (TableQueryOptions)any);
            result = empty;

            fileDataService.saveResultsFile((ResultsFile) any);

        }
    };

    resultsToCsvService.persistResultsAsCSV(id);

}
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing jmockit

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