Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Convert tests to jest#88

Merged
gregdyke merged 2 commits intoCodeYourFuture:mainfrom
gregdyke:jestify-js2w1
Jun 27, 2021
Merged

Convert tests to jest#88
gregdyke merged 2 commits intoCodeYourFuture:mainfrom
gregdyke:jestify-js2w1

Conversation

@gregdyke
Copy link
Copy Markdown
Contributor

@gregdyke gregdyke commented Jun 23, 2021

  • Added instructions for running in README
  • Added tests for calls to console.log in 1-writers and 8-reading-list
  • Clarified 6-people-I-know to distinguish friends and colleagues, rather than my friends and their friends
  • Added functions to be callable from tests where relevant
  • Did not cover 4-water-bottle, 7-recipes or 11-choose-your-own-adventure

View rendered README.md

- Added instructions for running in README
- Added tests for calls to console.log in 1-writers and 8-reading-list
- Clarified 6-people-I-know to distinguish friends and colleagues, rather than my friends and their friends
- Added functions to be callable from tests where relevant
- Did not cover 4-water-bottle, 7-recipes or 11-choose-your-own-adventure
@gregdyke gregdyke requested a review from a team June 23, 2021 01:19
@gregdyke
Copy link
Copy Markdown
Contributor Author

I notice I'm missing the license. I'll get round to that. I was wondering what the best approach might be for exercise 4-water-bottle. And I was wondering whether 7 and 11 were worth trying to create tests for.

7 might be a bit brittle depending on using \n in their console.logs (though I guess we say one console.log per line?)

11... I wonder if the source could be designed to run in two modes, based on whether the test function is defined (if yes we are in jest, if no we are in node?)

@gregdyke
Copy link
Copy Markdown
Contributor Author

@SallyMcGrath What do you think of consistently having the README instructions for running the tests to have this format?

Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

I was wondering what the best approach might be for exercise 4-water-bottle.

I think converting the existing "Do 100 things in a row and assert they all worked" into targeted unit tests which happen to share one global object (ick, but... It only has one field of state, and not teaching constructors feels worthwhile a at this point - at least JS is single-threaded!), where we force preconditions... I'm thinking of 10-ish tests along the lines of:

test("pouring full water bottle doesn't over-fill it", () => {
  bottle.volume = 100;
  bottle.pour();
  expect(bottle.volume).toEqual(100);
});
  

And I was wondering whether 7 [...] worth trying to create tests for.

I probably wouldn't bother... If we do test it, I would lean towards asserting on the structure, rather than the logs - something like:

  • Assert that the recipes object contains at least 5 properties
  • Assert that for each property it's an object containing a title string, a servings number, and a non-empty array of ingredient strings

If we were teaching them about classes/constructors, we could have a nice toString method we could test, but I suspect that's more hassle than it's worth.

11... I wonder if the source could be designed to run in two modes, based on whether the test function is defined (if yes we are in jest, if no we are in node?)

Could be interesting!

Comment thread mandatory/5-groceries.js Outdated
Comment thread mandatory/5-groceries.js Outdated
Comment thread mandatory/6-people-I-know.js Outdated
Comment thread mandatory/8-reading-list.js Outdated
Comment thread mandatory/8-reading-list.js
@gregdyke
Copy link
Copy Markdown
Contributor Author

Notes to self/what I'll follow up on in this PR

  • use toIncludeSameMembers where appropriate
  • fix typos
  • get concensus on whether including a solution in the description of how to regenerate the test literal is a good idea

Followup PR

  • tests for 4-bottles and 11-choose-your-own-adventure

Different Repos/tickets

  • Ticket about writing the followup to intro to testing, about red/green refactoring, to be optionally introduced in JS2 week 1 / plan to have more exercises like 8-reading-list that involve modifying tests
  • PR to solutions repo (already mostly done, just waiting til changes here are approved)
  • Maybe JS2 teaching note about option to prep students for 8-reading-list (maybe by doing live coding with TDD?)

@gregdyke
Copy link
Copy Markdown
Contributor Author

README: npm test is missing

Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thanks!

@gregdyke gregdyke merged commit b9a8fd4 into CodeYourFuture:main Jun 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants