tests/testthat/test-js.R

test_that( "js events can be chained ", {

  fns <- list(
    a = htmlwidgets::JS("function(a) { a  + 1 }"),
    b = htmlwidgets::JS("function(b) { b  + 3 }"),
    c = htmlwidgets::JS("function(c) { c  + 5 }")
  )

  js <- chain_js_events(
    NULL,
    fns$a,
    NULL,
    fns$b,
    fns$c,
    NULL,
    NULL
  )

  expect_equal(
    js,
    htmlwidgets::JS("function() {
  try {
    (function(a) { a  + 1 }).apply(this, arguments);
  } catch(e) {
    if (window.console && window.console.error) window.console.error(e);
  }

  try {
    (function(b) { b  + 3 }).apply(this, arguments);
  } catch(e) {
    if (window.console && window.console.error) window.console.error(e);
  }

  try {
    (function(c) { c  + 5 }).apply(this, arguments);
  } catch(e) {
    if (window.console && window.console.error) window.console.error(e);
  }
}")
  )


  js <- chain_js_events(
    NULL,
    fns$a,
    NULL
  )
  expect_equal(
    js, fns$a
  )

})

Try the sortable package in your browser

Any scripts or data that you put into this service are public.

sortable documentation built on March 31, 2023, 9:35 p.m.