Skip to content

Nested Describe Functions Fail #24

Description

@FlippieCoetser

According to Testhat Documentation, nesting describe() functions should be possible: link

Below is a copy of the example in the documentation

# Nested specs:
## code
addition <- function(a, b) a + b
division <- function(a, b) a / b

## specs
describe("math library", {
  describe("addition()", {
    it("can add two numbers", {
      expect_equal(1 + 1, addition(1, 1))
    })
  })
  describe("division()", {
    it("can divide two numbers", {
      expect_equal(10 / 2, division(10, 2))
    })
    it("can handle division by 0") #not yet implemented
  })
})

However, when trying to run the example in VS code, an error is thrown:

image

Removing the nesting like so:

## specs
describe("math library", { 
  it("can add two numbers", {
    expect_equal(1 + 1, addition(1, 1))
  })
  it("can divide two numbers", {
    expect_equal(10 / 2, division(10, 2))
  })
  it("can handle division by 0") #not yet implemented
})

Works as expected.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions