Class: Scarpe::TestPromise

Inherits:
Promise
  • Object
show all
Defined in:
lib/scarpe/wasm/control_interface_test.rb

Overview

A Promise but with helper functions

Instance Method Summary collapse

Constructor Details

#initialize(iface:, state: nil, wait_for: [], &scheduler) ⇒ TestPromise

Returns a new instance of TestPromise.



204
205
206
207
# File 'lib/scarpe/wasm/control_interface_test.rb', line 204

def initialize(iface:, state: nil, wait_for: [], &scheduler)
  @iface = iface
  super(state: state, parents: wait_for, &scheduler)
end

Instance Method Details

#inspectObject



209
210
211
# File 'lib/scarpe/wasm/control_interface_test.rb', line 209

def inspect
  "<#TestPromise::#{object_id} state=#{state.inspect} parents=#{parents.inspect} value=#{returned_value.inspect} reason=#{reason.inspect}>"
end

#then_ruby_promise(wait_for: [], &block) ⇒ Object

This method expects to wait for the parent TestPromise and then run a block of Ruby that returns another promise. This is useful for wrapping Promises like those from replace() that don’t have the test DSL built in. The block will execute when this outer promise is scheduled – so we don’t do a replace() too early, for instance. And then the outer promise will fulfill when the inner one does.



217
218
219
220
221
222
223
224
# File 'lib/scarpe/wasm/control_interface_test.rb', line 217

def then_ruby_promise(wait_for: [], &block)
  ruby_wrapper_promise = TestPromise.new iface: @iface, wait_for: ([self] + wait_for)

  ruby_wrapper_promise.on_scheduled do
    inner_ruby_promise = block.call
    inner_ruby_promise.on_fulfilled { ruby_wrapper_promise.fulfilled!(inner_ruby_promise.returned_value) }
  end
end

#then_with_js_dom_html(wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block) ⇒ Object



230
231
232
# File 'lib/scarpe/wasm/control_interface_test.rb', line 230

def then_with_js_dom_html(wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block)
  @iface.with_js_dom_html(wait_for: (wait_for + [self]), timeout:, &block)
end

#then_with_js_value(js_code, wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block) ⇒ Object



226
227
228
# File 'lib/scarpe/wasm/control_interface_test.rb', line 226

def then_with_js_value(js_code, wait_for: [], timeout: DEFAULT_ASSERTION_TIMEOUT, &block)
  @iface.with_js_value(js_code, wait_for: (wait_for + [self]), timeout:, &block)
end