6.2. Your turn
Please test the rest of the list yourself. For CounterStore:
- ignore invalid input: start from a value, type something that isn't a number, and check that the value stays.
- reset: any value goes back to 0.
And for Store:
- new store: one counter,
sumis 0, andcanAddMoreCountersis true. - add and remove counters:
addCounterstops at four, andremoveCountermakes room again.
Two matchers you haven't used yet:
expect(store.counters).toHaveLength(4);
expect(store.counters).not.toContain(counter);
.not turns any matcher around. Each test creates its own store, so the tests never get in each other's way.
Need a hint?
- new CounterStore(5) starts at 5, so you can check that setValue('abc') keeps it.
- removeCounter takes the counter itself, for example store.counters[0].
When all six tests pass, choose Show solution and compare. There's more than one good way to write them.