tests/testthat/test-search_meds.R

with_mock_dir("search_meds", {
  test_that("Returns data.frame", {
    oxy_list <- search_meds("oxy")
    expect_true(is.data.frame(oxy_list))
  })

  test_that("Able to retrieve all 6 medications with 'mcg' in the name", {
    mcg <- search_meds("mcg")
    expect_length(mcg$med_name, 6)
    expect_length(mcg$cf, 6)
  })
})

test_that("Provides correct error messages for invalid `med_name`", {
  expect_snapshot(
    error = TRUE,
    search_meds(med_name = NULL)
  )

  expect_snapshot(
    error = TRUE,
    search_meds(med_name = NULL)
  )

  expect_snapshot(
    error = TRUE,
    search_meds(med_name = 1)
  )

  expect_snapshot(
    error = TRUE,
    search_meds(med_name = c("fent", "tram"))
  )
})

Try the mmequiv package in your browser

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

mmequiv documentation built on June 8, 2025, 11:12 a.m.