Created
October 13, 2021 05:36
-
-
Save takahirohonda/9b3f64c03a6c5482a7fa7177552441d4 to your computer and use it in GitHub Desktop.
jest-data-provider-pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getAnimal = (sound) => { | |
switch(sound) { | |
case 'meow': | |
return 'Cat'; | |
case 'woof': | |
return 'Dog'; | |
case 'pawoo': | |
return 'Elephant'; | |
default: | |
return 'Human'; | |
} | |
}; | |
const animalDataProvider = [ | |
{ | |
input: 'meow', | |
expectedOutput: 'Cat' | |
}, | |
{ | |
input: 'woof', | |
expectedOutput: 'Dog' | |
}, | |
{ | |
input: 'pawoo', | |
expectedOutput: 'Elephant' | |
}, | |
{ | |
input: 'whatever', | |
expectedOutput: 'Human' | |
}, | |
]; | |
describe.each(animalDataProvider)('getAnimal', (data) => { | |
it(`should return correct animal with input '${data.input}'`, () => { | |
console.log(data.input); | |
const animal = getAnimal(data.input); | |
expect(animal).toEqual(data.expectedOutput); | |
} ) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment