Creating a Test Automation Harness for Jest with Typescript

Scenario

/**
* Test whether the target string contains the contained string.
*
* @param target The string that should contains the element
* @param contained The possibly contained string
* @return true if the `target` string contains the `contained` string, false otherwise
* @example
* ```
* expect(contains('foobar', 'foo')).toBeTruthy()
* ```
*/
export function contains(target: string, contained: string):boolean {
return target.indexOf(contained) >= 0;
}
test('contains', ()=>{
runtest(testdata, contains)
})

Approach

Harness

const testdata: TestData[] = [{it: 'should test contains',args: ['foo'],valid: ['foo', 'foobar', 'bazfoo'],invalid: ['bar', 'fobar'],}]
each: ['baz', 'bar', 'beech']

The TestData interface

export interface TestData {it: stringargs?: anyeach?: any[]valid: any[],invalid: any[]}

Test Utility Function

More Examples

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store