Skip to content

Commit 3408404

Browse files
committed
Fix the history spec
1 parent d24f7a0 commit 3408404

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

spec/history_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
promise = Promise.new
2828

29-
$window.on 'pop:state' do |e|
30-
e.off
31-
29+
$window.one 'pop:state' do |e|
3230
expect($window.history.current).to eq('/')
3331
promise.resolve
3432
end
@@ -40,21 +38,23 @@
4038

4139
describe '#state' do
4240
it 'gets the right state' do
43-
$window.history.push('/wut', 42)
44-
$window.history.state.should eq(42)
45-
$window.history.push('/omg', 23)
46-
$window.history.state.should eq(23)
47-
41+
# XX: The previous test creates a race condition with this one.
42+
# Adding a delay fixes it.
4843
promise = Promise.new
4944

50-
$window.on 'pop:state' do |e|
51-
e.off
45+
after 0.05 do
46+
$window.history.push('/wut', 42)
47+
$window.history.state.should eq(42)
48+
$window.history.push('/omg', 23)
49+
$window.history.state.should eq(23)
5250

53-
expect(true).to eq(true)
54-
promise.resolve
55-
end
51+
$window.one 'pop:state' do |e|
52+
expect(true).to eq(true)
53+
promise.resolve
54+
end
5655

57-
$window.history.back(2)
56+
$window.history.back(2)
57+
end
5858
promise
5959
end
6060
end if Browser.supports? 'History.state'

0 commit comments

Comments
 (0)