Skip to content

Instantly share code, notes, and snippets.

@bahmutov
Last active April 7, 2016 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahmutov/35838baa52329c411a442d59fbd0edd2 to your computer and use it in GitHub Desktop.
Save bahmutov/35838baa52329c411a442d59fbd0edd2 to your computer and use it in GitHub Desktop.
Grid of individual tests
// if our data is more complicated and has to form things from items for example
// just pass around list of functions
const API = {
github: (username) => 'http://github.com/' + username,
photo: (username) => `http://github.com/${username}/avatar/`
}
const users = ['bahmutov', 'adity']
Object.keys(API).forEach((apiName) => {
const formApiUrl = API[apiName]
describe('api ' + apiName, () => {
users.forEach((user) => {
const url = formApiUrl(user)
// assert url works
})
})
})
// simple static data1 / data2 grid
function length(x) { return x.length }
function double(x) { return x + x }
const items = ['foo', 'bar', 'baz']
const actions = [length, double]
actions.forEach((action) => {
describe(action.name, () => {
items.forEach((item) => {
it('is computes truthy for item ' + item, () => {
la(action(item), 'failed action', action.name, 'for item', item)
})
})
})
})
@bahmutov
Copy link
Author

bahmutov commented Apr 7, 2016

will output something like this

length
  - it computes truthy for foo
  - it computes truthy for bar
  - it computes truthy for baz
double
  - it computes truthy for foo
  - it computes truthy for bar
  - it computes truthy for baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment