UNPKG

skutter

Version:

Skutter: Opinionated BDD Browser based test framework

69 lines (68 loc) 3.21 kB
"use strict"; const Yadda = require("yadda"); var English = Yadda.localisation.English; const iskutter_library_1 = require("./iskutter-library"); const dictionary_converter_1 = require("./services/dictionary-converter"); const macro_wrapper_factory_1 = require("./services/macro-wrapper-factory"); class SkutterLibrary { constructor(dictionary) { this.dictionary = dictionary; let yaddaDict = dictionary ? dictionary_converter_1.DictionaryConverter.convert(dictionary) : null; this.yaddaLibrary = English.library(yaddaDict); } getYaddaLibrary() { return this.yaddaLibrary; } given(givenDefinition, code) { let stepDefinition = null; if (typeof (givenDefinition) === "string") { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.given, givenDefinition); } else if (Array.isArray(givenDefinition)) { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.given, givenDefinition); } else { if (givenDefinition.type !== iskutter_library_1.StepType.given) { throw new Error(`Step definition of type '${givenDefinition.type}' provided when 'given' was expected.`); } stepDefinition = givenDefinition; } this.yaddaLibrary.given(stepDefinition.text, macro_wrapper_factory_1.MacroWrapperFactory.wrap(code)); return this; } when(whenDefinition, code) { let stepDefinition = null; if (typeof (whenDefinition) === "string") { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.when, whenDefinition); } else if (Array.isArray(whenDefinition)) { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.when, whenDefinition); } else { if (whenDefinition.type !== iskutter_library_1.StepType.when) { throw new Error(`Step definition of type '${whenDefinition.type}' provided when 'when' was expected.`); } stepDefinition = whenDefinition; } this.yaddaLibrary.when(stepDefinition.text, macro_wrapper_factory_1.MacroWrapperFactory.wrap(code)); return this; } then(thenDefinition, code) { let stepDefinition = null; if (typeof (thenDefinition) === "string") { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.then, thenDefinition); } else if (Array.isArray(thenDefinition)) { stepDefinition = new iskutter_library_1.StepDefinition(iskutter_library_1.StepType.then, thenDefinition); } else { if (thenDefinition.type !== iskutter_library_1.StepType.then) { throw new Error(`Step definition of type '${thenDefinition.type}' provided when 'then' was expected.`); } stepDefinition = thenDefinition; } this.yaddaLibrary.then(stepDefinition.text, macro_wrapper_factory_1.MacroWrapperFactory.wrap(code)); return this; } } exports.SkutterLibrary = SkutterLibrary;