我正在用摩卡和酶测试反应成分.这是组件(当然简化为简化):
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) 我想让一个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岁.
我的测试是使用灯具编写的,我正在慢慢地重构它们以使用工厂.
一旦我重构了一个不使用灯具的测试类,我就不想加载那个类的灯具了.有没有办法做到这一点?或者我是坚持要么加载他们的一切或什么都没有?
对于上下文,以下是我的灯具现在如何设置:
class ActiveSupport::TestCase
Rake::Task["db:fixtures:load"].execute
...
end
Run Code Online (Sandbox Code Playgroud) 我有两个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) 我正在使用 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 }))并确认那里确实存在有效数据并调用了一个属性。
anaconda ×1
bash ×1
conda ×1
cron ×1
enzyme ×1
fixtures ×1
javascript ×1
minitest ×1
mocha.js ×1
python ×1
react-apollo ×1
reactjs ×1
ruby ×1
typescript ×1