cse110-sp23-group21 / map-my-future

CSE 110 (Software Engineering) Team Project
1 stars 1 forks source link

Add Test Cases to Cartomancy mini-app #81

Closed gilkeidar closed 1 year ago

gilkeidar commented 1 year ago

Task Description: Add Jest unit tests to the Cartomancy mini-app.

Note: You cannot call fetch() in Jest unit tests. This includes testing whether a JSON file was read correctly by the FortuneEngine.

If you want to test a feature that relies on the FortuneEngine, do the following:

  //  Create a FortuneEngine object
  const engine = new FortuneEngine('Test');

  //  Can't test fetch() in Jest - assume read.
  engine.initialized = true;

  //  Set JSON contents
  const jsonContents = {
      // insert your JSON file's contents here
  };

  engine.json_contents = jsonContents;

  const outcomes = engine.json_contents['option-result pair'];

  engine.outcomes = outcomes;

  // can safely call get_random_subset() now

Is it gross? Yes. But Jest is made for unit testing - I believe we need end-to-end testing support to facilitate testing of this kind.