小编sto*_*elj的帖子

酶模拟onChange事件

我正在用摩卡和酶测试反应成分.这是组件(当然简化为简化):

class New extends React.Component {

  // shortened for simplicity

  handleChange(event) {
    // handle changing state of input

    const target = event.target;
    const value = target.value;
    const name = target.name
    this.setState({[name]: value})

  }


  render() {
    return(
      <div>
        <form onSubmit={this.handleSubmit}>
          <div className="form-group row">
            <label className="col-2 col-form-label form-text">Poll Name</label>
            <div className="col-10">
              <input
                className="form-control"
                ref="pollName"
                name="pollName"
                type="text"
                value={this.state.pollName}
                onChange={this.handleChange}
              />
            </div>
          </div>

          <input className="btn btn-info"  type="submit" value="Submit" />
        </form>
      </div>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是测试:

it("responds to name change", done => {
  const handleChangeSpy …
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js reactjs enzyme

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

使用annaconda env运行crontab作业

我想让一个cron作业使用一个名为my_env的现有anaconda python环境执行python脚本.我唯一能想到的就是让cron作业运行一个脚本调用my_script.bash,然后激活env,然后运行python脚本.

#!/bin/bash
source activate my_env
python ~/my_project/main.py
Run Code Online (Sandbox Code Playgroud)

尝试从命令行执行此脚本不起作用:

$ sh scripts/my_script.bash
scripts/my_script.bash: 9: scripts/my_script.bash: source: not found
Run Code Online (Sandbox Code Playgroud)

我需要做些什么来确保激活适当的环境.可以向我解释,就像我5岁.

python bash cron anaconda conda

22
推荐指数
4
解决办法
9002
查看次数

rails/minitest不为选择的测试加载灯具

我的测试是使用灯具编写的,我正在慢慢地重构它们以使用工厂.

一旦我重构了一个不使用灯具的测试类,我就不想加载那个类的灯具了.有没有办法做到这一点?或者我是坚持要么加载他们的一切或什么都没有?

对于上下文,以下是我的灯具现在如何设置:

class ActiveSupport::TestCase
   Rake::Task["db:fixtures:load"].execute
   ...
end
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails fixtures minitest

8
推荐指数
2
解决办法
803
查看次数

测试ActiveRecord :: Relation的相等性

我有两个ActiveRecord:Relation对象:

actual
#=> #<ActiveRecord::Relation [#<AdmTep id: 587730567, Student_Bnum: "145919559", Program_ProgCode: "750600237", BannerTerm_BannerTerm: 201511, Attempt: 1, GPA: 2.75, GPA_last30: 3.0, EarnedCredits: 30, PortfolioPass: nil, TEPAdmit: true, TEPAdmitDate: nil, Notes: nil, letter_file_name: "letter.docx", letter_content_type: nil, letter_file_size: nil, letter_updated_at: nil>]>
expected
#=> #<ActiveRecord::Relation [#<AdmTep id: 587730567, Student_Bnum: "145919559", Program_ProgCode: "750600237", BannerTerm_BannerTerm: 201511, Attempt: 1, GPA: 2.75, GPA_last30: 3.0, EarnedCredits: 30, PortfolioPass: nil, TEPAdmit: true, TEPAdmitDate: nil, Notes: nil, letter_file_name: "letter.docx", letter_content_type: nil, letter_file_size: nil, letter_updated_at: nil>]>
Run Code Online (Sandbox Code Playgroud)

每个包含一条记录,这些记录通过==测试,

actual.size #=> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

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

打字稿/阿波罗:从内存缓存中访问属性

我正在使用 Apollo Client 并且正在学习 Typescript。我有一个Mutation带有此更新道具的组件:

(cache, { data: { createTask } }) => {
    const allTasks = cache.readQuery({ query: ALL_TASKS }).allTasks;
}
Run Code Online (Sandbox Code Playgroud)

我收到两个编译错误:

Object is possibly 'null'.
Property 'allTasks' does not exist on type '{}'.
Run Code Online (Sandbox Code Playgroud)

我理解总体思路。readQuery可能会返回null(这是自我混淆,因为文档让我相信当没有找到结果时会抛出错误(https://www.apollographql.com/docs/react/advanced/caching.html#readquery)。

我怎样才能让编译器让我allTasks从结果中读取属性readQuery

另外,仅供参考,我尝试运行console.log(cache.readQuery({ query: ALL_TASKS }))并确认那里确实存在有效数据并调用了一个属性。

typescript react-apollo apollo-client

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