import { cucumber } from '../lib' ; import { HookType , FeatureContext } from 'stucumber' ; import * as fs from 'fs' ; import * as path from 'path' ; interface World { a ? : number ; b ? : number ; answer ? : number ; } cucumber . defineCreateWorld ( ( ) => ( { a : null , b : null , answer : null } ) ) ; cucumber . defineRule ( /^I have numbers (\d+) and (\d+)$/ , ( world , a , b ) => { return new Promise ( resolve => { process . nextTick ( ( ) => { world . a = parseInt ( a ) ; world . b = parseInt ( b ) ; resolve ( ) ; } ) ; } ) ; } ) ; cucumber . defineRule ( /^I (add|subtract|multiply|divide) them$/ , ( world , op ) => { switch ( op ) { case 'add' : world . answer = world . a + world . b ; break ; case 'subtract' : world . answer = world . a - world . b ; break ; case 'multiply' : world . answer = world . a * world . b ; break ; case 'divide' : world . answer = world . a / world . b ; break ; } } ) ; cucumber . defineRule ( /^I get (\d+)$/ , ( world , answer ) => { expect ( world . answer ) . toBe ( parseInt ( answer ) ) ; } ) ;