在使用假定时器和承诺的组合时,我在使用Jest测试框架(版本23.2.0)时能够很好地工作.我哪里错了?
假设我有以下模块:
// timing.js
export const timeout = ms =>
new Promise(resolve => {
setTimeout(resolve, ms)
})
Run Code Online (Sandbox Code Playgroud)
我的测试文件看起来像:
// timing.test.js
import { timeout } from './timing'
describe('timeout()', () => {
beforeEach(() => {
jest.useFakeTimers()
})
it('resolves in a given amount of time', () => {
const spy = jest.fn()
timeout(100).then(spy)
expect(spy).not.toHaveBeenCalled()
jest.advanceTimersByTime(100)
expect(spy).toHaveBeenCalled()
})
})
Run Code Online (Sandbox Code Playgroud)
这失败,输出如下:
? timeout › resolves in a given amount of time
expect(jest.fn()).toHaveBeenCalled()
Expected mock function to have been called, but it was not called.
15 …Run Code Online (Sandbox Code Playgroud) 我目前正在对一个站点进行可访问性大修,但遇到了一个我不知道如何在 Rails 中解决的问题。代码如下:
<%= f.label :birthdate %>
<%= f.date_select :birthdate, {:start_year => Time.now.year - 14, :end_year => 1900, :prompt => true, :order => [:day, :month, :year]} %>
Run Code Online (Sandbox Code Playgroud)
其中产生:
<label for="birthdate">Birthdate</label>
<select id="birthdate_3i" name="birthdate(3i)">
<option value="">Day</option>
<option value="1">1</option>
...
<option value="31">31</option>
</select>
<select id="birthdate_2i" name="birthdate(2i)">
<option value="">Month</option>
<option value="1">January</option>
...
<option value="12">December</option>
</select>
<select id="birthdate_1i" name="birthdate(1i)">
<option value="">Year</option>
<option value="1998">1998</option>
...
<option value="1900">1900</option>
</select>
Run Code Online (Sandbox Code Playgroud)
有谁知道我是否必须为已生成的 3 个选择字段手动编写标签/字段集?或者我应该以不同的方式使用 rails 代码。我对 Rails 有点陌生……更像是一个前端。