Repeated Specs / Series of Specs

20 views
Skip to first unread message

Dirk Toewe

unread,
Dec 11, 2018, 11:46:13 AM12/11/18
to Jasmine
Hi everyone,

is there any way to execute a spec for each element in an iterable, without either
  1.   blowing up the number of specs or
  2.   writing an async spec that uses
    await new Promise( f => sefTimeout(f) )
     to keep the browser responsive?
What I have in mind is something like:

describe('is_even', () => {
 
function* even_positive_integers(){
   
for( let i=0; i < Number.MAX_SAFE_INTEGER; i+=2 )
     
yield i
 
}
  for_each_item_in
( even_positive_integers() ).it('should return true', item => expect(is_even(item)).toBe(true) )
})

Something like this would be really useful for:
  • Exhaustive testing of every combination of inputs/states
  • Randomized testing that unveils bugs You haven't even dreamt about.
I already checked the Jasmine docs and the usual suspects and couldn't find anything like that. One simple implementation of the above I can think of is:

const for_each_item_in = items => ({
  it
: (specText, specFn) => it(specText, async () => {
   
for( const item of items )
   
{
      await
new Promise( done => setTimeout(done) )
      specFn
(item)
   
}
 
})
})

But the problem with this implementation is that it is impossible to tell for which item in the iterable the failure occoured.

Maybe somebody here knows a better way?

Help would be appreciated
Dirk


Reply all
Reply to author
Forward
0 new messages