Skip to content

Commit

Permalink
fix: remove expect_snapshot() by expect_errors in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddotta committed May 23, 2024
1 parent 17840ea commit 5e12edb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 163 deletions.
66 changes: 0 additions & 66 deletions tests/testthat/_snaps/add_table.md

This file was deleted.

49 changes: 0 additions & 49 deletions tests/testthat/_snaps/asserts.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,7 @@
# assert_class function works as expected

Code
assert_class(x, "matrix", TRUE)
Error <simpleError>
x must be of class matrix or null

# assert_character1 function works as expected

Code
assert_character1(c("1", "2"))
Error <simpleError>
c12 must be a character vector of length 1L

---

Code
assert_character1(1)
Error <simpleError>
1 must be a character vector of length 1L

# assert_numeric1 function works as expected

Code
assert_numeric1(c(1, 2))
Error <simpleError>
c must be a numeric vector of length 1L1 must be a numeric vector of length 1L2 must be a numeric vector of length 1L

---

Code
assert_numeric1("1")
Error <simpleError>
1 must be a numeric vector of length 1L

---

Code
assert_numeric1(c(1, 2), scalar = TRUE)
Error <simpleError>
c must be a single number1 must be a single number2 must be a single number

# assert_named_list function works as expected

Code
assert_named_list(x)
Error <simpleError>
x must be a named list

# assert_named_list_in_list function works as expected

Code
assert_named_list_in_list(x)
Error <simpleError>
x must be a list composed of one or more lists of which all elements must be named

45 changes: 18 additions & 27 deletions tests/testthat/test-add_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ test_that("add_table function throws error when passing invalid data type for Ta
SheetTitle <- "Sheet1"
TableTitle <- "Test Table"

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle)
)
})

Expand All @@ -18,9 +17,8 @@ test_that("add_table function throws error when passing invalid data type for Wb
SheetTitle <- "Sheet1"
TableTitle <- "Test Table"

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle)
)
})

Expand All @@ -31,9 +29,8 @@ test_that("add_table function throws error when passing invalid data type for Sh
SheetTitle <- 123
TableTitle <- "Test Table"

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle)
)
})

Expand All @@ -44,9 +41,8 @@ test_that("add_table function throws error when passing invalid data type for Ta
SheetTitle <- "Sheet1"
TableTitle <- 123

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle)
)
})

Expand All @@ -58,9 +54,8 @@ test_that("add_table function throws error when passing invalid data type for St
TableTitle <- "Test Table"
StartRow <- "1"

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle, StartRow),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle, StartRow)
)
})

Expand All @@ -72,9 +67,8 @@ test_that("add_table function throws error when passing invalid data type for St
TableTitle <- "Test Table"
StartCol <- "1"

expect_snapshot(
add_table(Table, WbTitle, SheetTitle, TableTitle, StartCol = StartCol),
error = TRUE
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle, StartCol = StartCol)
)
})

Expand All @@ -90,12 +84,11 @@ test_that("add_table function throws error when passing invalid data type for Ta
FormatList <- list()
TableFootnote1 <- 123

expect_snapshot(
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle,
StartRow, StartCol, FormatList,
TableFootnote1 = TableFootnote1
),
error = TRUE
)
)
})

Expand All @@ -110,12 +103,11 @@ test_that("add_table function throws error when passing invalid data type for Ta
FormatList <- list()
TableFootnote2 <- 123

expect_snapshot(
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle,
StartRow, StartCol, FormatList,
TableFootnote2 = TableFootnote2
),
error = TRUE
)
)
})

Expand All @@ -130,12 +122,11 @@ test_that("add_table function throws error when passing invalid data type for Ta
FormatList <- list()
TableFootnote3 <- 123

expect_snapshot(
expect_error(
add_table(Table, WbTitle, SheetTitle, TableTitle, StartRow, StartCol,
FormatList,
TableFootnote3 = TableFootnote3
),
error = TRUE
)
)
})

Expand Down
41 changes: 20 additions & 21 deletions tests/testthat/test-asserts.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ test_that("assert_class function works as expected", {

# Test 5: assert_class returns an error
x <- list()
expect_snapshot(
assert_class(x, "matrix", TRUE),
error = TRUE)
expect_error(
assert_class(x, "matrix", TRUE)
)
})

test_that("assert_character1 function works as expected", {
Expand All @@ -32,14 +32,13 @@ test_that("assert_character1 function works as expected", {
expect_true(TRUE)

# Test 2: assert_character1 returns an error with character vector and several elements
expect_snapshot(
assert_character1(c("1","2")),
error = TRUE)
expect_error(
assert_character1(c("1","2"))
)

# Test 3: assert_character1 returns an error with numeric input
expect_snapshot(
assert_character1(1),
error = TRUE)
expect_error(
assert_character1(1))
})

test_that("assert_numeric1 function works as expected", {
Expand All @@ -52,19 +51,19 @@ test_that("assert_numeric1 function works as expected", {
expect_true(TRUE)

# Test 3: assert_numeric1 returns an error with numeric vector and several elements
expect_snapshot(
assert_numeric1(c(1,2)),
error = TRUE)
expect_error(
assert_numeric1(c(1,2))
)

# Test 4: assert_numeric1 returns an error with character input
expect_snapshot(
assert_numeric1("1"),
error = TRUE)
expect_error(
assert_numeric1("1")
)

# Test 5: assert_numeric1 returns an error with numeric vector and several elements and scalar as true
expect_snapshot(
assert_numeric1(c(1,2),scalar = TRUE),
error = TRUE)
expect_error(
assert_numeric1(c(1,2),scalar = TRUE)
)
})

test_that("assert_named_list function works as expected", {
Expand All @@ -88,9 +87,9 @@ test_that("assert_named_list_in_list function works as expected", {

# Test 2: assert_named_list_in_list returns an error with a simple named list
x <- list("elem1" = "a")
expect_snapshot(
assert_named_list_in_list(x),
error = TRUE)
expect_error(
assert_named_list_in_list(x)
)
})

test_that("assert_grouped function works as expected", {
Expand Down

0 comments on commit 5e12edb

Please sign in to comment.