moonpie.test_helpers

Test helpers and extra assertions are provided for the Busted <http://olivinelabs.com/busted/> testing framework.

Array Extensions

A number of array helpers are available:

it("has some array elements", function()
  local test = { 1, 2, 3, 4 }
  assert.array_includes(1, test)
end)

Mock Store

Mocks the redux style store that manages state. Allowing easier testing of components that are dependent on the store.

describe("My test harness", function()
  local mock_store = require "moonpie.test_helpers.mock_store"
  local initial_state = { values = true }
  local store = mock_store(initial_state)

  it("can track dispatches", function()
    system_under_test.do_thing_that_dispatches()
    assert.equals(1, #store.get_actions("action_type"))
  end)
end)

General helpers

spy_to_func
Converts a spy routine into a pure function. This can be helpful in situations where the code under test responds differently to tables vs functions.