小编Sea*_*ean的帖子

单元测试需要OAuth令牌的API

我正在尝试编写一套自动集成测试来测试我对Yahoo Fantasy Sports API的 C#客户端库调用.一些API调用需要OAuth令牌,这是我遇到一些困难的地方.我可以使用Web浏览器生成访问密钥和密码,然后在我的测试代码中传递它们,但令牌在一小时后过期,所以我需要手动重新生成这些并在我想运行时更新我的​​测试配置试验.

当需要OAuth令牌时,是否有编写API集成测试的最佳实践?

c# yahoo unit-testing oauth

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

如何在Visual Studio中禁用Task Runner Explorer?

Task Runner Explorer只会在Visual Studio 2015 RC中为我抛出错误,我只是想禁用它并像我一样从命令行运行gulp文件.有没有办法关闭Task Runner Explorer?

gulp visual-studio-2015 task-runner-explorer

9
推荐指数
3
解决办法
7400
查看次数

反应 div 容器 onClick 与复选框 onChange 冲突

在下面的 React 类中,我在 div 容器中有一个复选框。我想点击容器来切换复选框。我还认为我需要绑定复选框输入本身的 onChange,以处理诸如当用户使用 Tab/spacing 来切换复选框状态之类的事情(如果我没有指定 onChange,我也会从 React 收到警告,因为这是一个受控组件)。

我的问题是当我单击复选框本身时,两个事件处理程序都会触发,因此复选框的状态实际上并没有改变。我在 handleCheckboxChange 中尝试过 e.preventDefault 和 e.stopPropagation 但似乎都没有做任何事情。

export default class Item extends React.Component{
    constructor(){
        super();
        this.state={
            IsSelected: false
        }
    }
    render(){
        return (
            <div className="item">
                <div className="checkbox-container" onClick={this.handleContainerClick.bind(this)}>
                    <input type="checkbox" checked={this.state.IsSelected} onChange={this.handleCheckboxChange.bind(this)} />
                </div>                  
            </div>
        );
    }
    handleCheckboxChange(e){
        this.setState({
            IsSelected: !this.state.IsSelected
        });
    }
    handleContainerClick(){
        this.setState({
            IsSelected: !this.state.IsSelected
        });     }
}
Run Code Online (Sandbox Code Playgroud)

reactjs

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

npm 取消链接所有链接的全局模块

我可以运行它来列出我通过以下方式全局链接的所有 npm 模块npm link ...

npm ls -g --depth=0 --link=true

那么我该如何删除/取消链接所有这些链接的模块呢?我有超过 10 个依赖项,所以我正在寻找比运行npm unlink [module]10 次更令人满意的东西。

javascript node.js npm

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

是否可以在ReactJS中的表格单元格上设置CSSTransitionGroup?

考虑一下这个JSX结构:

<table>
  <tbody>
    <tr>
      <td>{this.props.firstName}</td>
      <td>{this.props.lastName}</td>
    </tr>
  </tbody>  
</table>
Run Code Online (Sandbox Code Playgroud)

我希望使用CSSTransitionGroup在其中一个道具更新时设置td的背景颜色,如下所示:

<table>
  <tbody>
    <tr>
      <ReactCSSTransitionGroup transitionName="example">
        <td key={this.props.firstName}>{this.props.firstName}</td>
      </ReactCSSTransitionGroup>
      <td>{this.props.lastName}</td>
    </tr>
  </tbody>  
</table>
Run Code Online (Sandbox Code Playgroud)

这里的问题是ReactCSSTransitionGroup呈现为span,它不是表行的有效子.那么React可以在表格单元格上设置进入/离开动画吗?

css3 css-transitions react-jsx

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

Babel 递归转译

设想

考虑以下目录结构

/views
  /one.js
  /two.js
/components
  /Header.js
  /Footer.js
/other
  ...
Run Code Online (Sandbox Code Playgroud)

我需要/views用 Babel 转译目录。我以编程方式执行此操作,但等效的 cli 命令如下所示:

babel views --out-dir .views

但该/views目录下的文件依赖于其他目录下的文件,即

/*
  views/one.js
*/

const Header = require('../components/Header');
...
Run Code Online (Sandbox Code Playgroud)

鉴于这种依赖性,我也需要/components/Header.js进行转译。

问题

我如何使用 Babel(可能与另一个库一起使用)转译指定的目录任何递归依赖项,而不转译整个代码库(例如/other等)?

javascript node.js babeljs

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

React:使用props和state控制输入值

给定具有受控输入的React组件,我希望能够:

  1. 设置父项状态的输入值
  2. 允许用户将输入更改为任何值
  3. 仅在用户提交并输入通过验证后才更新父级的状态.

我可以使用下面的代码片段完成1和2,但由于值通过props进入ChildComponent,我不确定如何在更改父项的myInput 值的情况下更改输入值.

class ChildComponent extends React.Component
{
    render(){
        return <input type="text" value={this.props.inputValue} onChange={this.handleChange.bind(this)} />
    }  
    handleChange(e){
        this.props.onInputChange(e.target.value);
    }
    handleSubmit(){
        // do some validation here, it it passes...
        this.props.handleSubmit();
    }
}

class ParentComponent extends React.Component{
    constructor(){
      super();
      this.state = {myInput: ""};
    }
    render(){
        return <ChildComponent inputValue={this.state.myInput} onInputChange={this.handleChange.bind(this)} />
    }
    handleChange(newValue){
        this.setState({myInput: newValue});
    }
    handleSubmit(){
        // do something on the server
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

ReactJS setState具有多个嵌套数组

考虑以下结构:

this.state = {
  States: [{
    Abbreviation: "MA",
    Cities: [{
      ID: 1,
      Name: "Boston",
      PropertyToUpdate: null
    },
    {
      ID: 2,
      Name: "Springfield",
      PropertyToUpdate: null
    }]
  }]
}
Run Code Online (Sandbox Code Playgroud)

给定城市ID和值,我需要将PropertyToUpdate属性更新为该值.所以我会有一个看起来像这样的函数:

handleUpdateProperty(cityID, newValue){
  // Do some things
  this.setState({...});
}
Run Code Online (Sandbox Code Playgroud)

我已经对不可变助手进行了一些阅读,但我不确定如何处理这两层嵌套.我认为应该看起来像:

var newState = React.addons.update(
  this.state.States[indexOfState].Cities[indexOfCity],
  {PropertyToUpdate: {$set: newValue}}
);
Run Code Online (Sandbox Code Playgroud)

...但这不是正确的语法.那么如何保持我的状态不可变,但仍然更新数组项的这个嵌套属性?

immutability reactjs

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