Skip to content

Testing Documentation

Johny Georges edited this page Dec 2, 2017 · 3 revisions

Testing in Mathbook

There are three types of tests that we create.

Functional Tests

Functional tests are tests that cover a small and functional piece of code ie) a transform or helper function.

To elaborate, we write a test suite for a function that accepts a certain input and returns a certain output. These tests tend to be straightforward to create as we only need to mock the input.

Note that if you have to stub out some dependency for the function you are trying to test, then that does not qualify as a functional test.

For example, we have what's called an errorTransformer in the source code.

function(err, source, params = {}) {
  err["details"] = {
    source: source,
    params: params
  }
  return err
}

It's very simple and easy to test.

it("should return an error with a details property that contains source and params properties", () => {
   const mockError = new Error("testing error")
   const mockSource = "source::of:truth"
   const mockParams = { foo: "hello", bar: "world" }
   
   const result = errorTransformer(mockError, mockSource, mockParams)
   expect(result).instanceOf(Error)
   expect(result).to.have.property("details")
   expect(result.details).to.have.property("source", mockSource) // the key is "source" and the value === mockSource
   expect(result.details).to.have.property("params", mockParams) // the key is "params" and the value === mockParams
})

Clone this wiki locally