Skip to content

Commit

Permalink
In class code for recycler
Browse files Browse the repository at this point in the history
  • Loading branch information
devonoel committed Jun 25, 2019
1 parent d1fbfb5 commit b512d8c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
57 changes: 56 additions & 1 deletion 37-what-to-test/recycler-js/recycler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,65 @@ test('getRandomJunk returns a string', () => {
});

test('getRandomJunk returns an array of number length when given a number', () => {
// fill this in
//arrange
let num = 3;
//act
let junk = getRandomJunk(num);
//assert
expect(junk.length).toEqual(3);
});

test('getRandomJunk returns an empty array when given a string as an argument', () => {
let junk = getRandomJunk("foo");
expect(junk).toEqual([]);
});

test('isCompostable returns true if item in food array', () => {
// expect(isCompostable('Moldy Bread')).toEqual(true);
expect(isCompostable('Moldy Bread')).toBeTruthy();
});

test('isCompostable returns false when item is not in food array', () => {
expect(isCompostable('Something Else')).toBeFalsy();
})

test('isRecyclable returns true if item in plastic array', () => {
expect(isRecyclable('Soda Bottle')).toBeTruthy();
});

test('isRecyclable returns true if item in paper array', () => {
expect(isRecyclable('Newspaper')).toBeTruthy();
});

test('isRecyclable returns true if item in metal array', () => {
expect(isRecyclable('Soda Can')).toBeTruthy();
});

test('isRecyclable returns true if item in glass array', () => {
expect(isRecyclable('Glass Bottle')).toBeTruthy();
});

test('isRecyclable returns false if item is something else', () => {
expect(isRecyclable('Black Plastic')).toBeFalsy();
});

test('emptyMaterial returns starting material values', () => {
//arrange
//act
let material = emptyMaterial();
//assert
expect(material).toEqual({
garbage: 0, compost: 0, metal: 0, glass: 0, paper: 0, plastic: 0
});
});

test('emptyMaterial updates material variable to initial value', () => {
//arrange
toss(["Old Shoes", "Black Plastic"]);
//act
emptyMaterial();
//assert
expect(getMaterial()).toEqual({
garbage: 0, compost: 0, metal: 0, glass: 0, paper: 0, plastic: 0
});
});
3 changes: 3 additions & 0 deletions 37-what-to-test/recycler-js/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Test the public interface (ie. functions being exported)
- Test for return values and updates to state (ie. side effects, or updates to variables)
- Test all possible outcomes (ie. if statements)

0 comments on commit b512d8c

Please sign in to comment.