tests/testthat/test-app.R

test_that("application", {
  library(ambiorix)

  app <- Ambiorix$new()

  app$get("/", function(req, res) {
    res$send("home")
  })

  app$post("/", function(req, res) {
    res$send("home")
  })
  
  app$put("/", function(req, res) {
    res$send("home")
  })

  app$patch("/", function(req, res) {
    res$send("home")
  })

  app$delete("/", function(req, res) {
    res$send("home")
  })

  app$all("/", function(req, res) {
    res$send("home")
  })

  app$options("/", function(req, res) {
    res$send("home")
  })

  # dynamic
  app$get("/.path", function(req, res) {
    res$send("home")
  })

  app$receive("message", function(...) {
    print("received")
  })

  expect_type(app$get_routes(), "list")
  expect_length(app$get_routes(), 8L)
  expect_snapshot(app)

  stop_all()
})

Try the ambiorix package in your browser

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

ambiorix documentation built on April 3, 2025, 9:34 p.m.