Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should throw an error when there is no macro by name provided', () => {
const step = new Step('And', 'macro test2 is executed');
expect(() => macro.onStep(step)).to.throw(Error)
});
it('should throw an error when a macro name is already defined', () => {
const scenario = new Scenario();
const scenario_2 = new Scenario();
const tag = new Tag('@macro(testname)');
const step = new Step('Given', 'step');
scenario.tags.push(tag);
scenario_2.tags.push(tag);
scenario.steps.push(step);
macro.macros.testname = scenario;
expect(() => macro.preFilterScenario(scenario_2)).to.throw(Error);
});
it('should process macro steps', () => {
const scenario_macro = new Scenario();
const tag = new Tag('@macro(test)');
const step_macro = new Step('When', 'test step');
const step_test = new Step('And', 'macro test is executed');
scenario_macro.tags.push(tag);
scenario_macro.steps.push(step_macro);
macro.preFilterScenario(scenario_macro);
expect(macro.onStep(step_test)).to.eql(scenario_macro.steps);
});
it('should throw an error when a macro contains a macro step', () => {
const scenario = new Scenario();
const tag = new Tag('@macro(test)');
const step = new Step('And', 'macro test is executed');
scenario.tags.push(tag);
scenario.steps.push(step);
expect(() => macro.preFilterScenario(scenario)).to.throw(Error)
});
it('should not change non macro steps', () => {
const step = new Step('Given', 'random step');
expect(macro.onStep(step)).to.eql(undefined);
});
it('should throw an error when name is not provided for macro', () => {
const step = new Step('And', 'macro is executed');
expect(() => {
macro.onStep(step);
}).to.throw(Error)
});
it('should process macro steps', () => {
const scenario_macro = new Scenario();
const tag = new Tag('@macro(test)');
const step_macro = new Step('When', 'test step');
const step_test = new Step('And', 'macro test is executed');
scenario_macro.tags.push(tag);
scenario_macro.steps.push(step_macro);
macro.preFilterScenario(scenario_macro);
expect(macro.onStep(step_test)).to.eql(scenario_macro.steps);
});
it('should process macro scenarios', () => {
const scenario = new Scenario();
const tag = new Tag('@macro(test_tag)');
const step = new Step('Given', 'random step');
scenario.tags.push(tag);
scenario.steps.push(step);
macro.preFilterScenario(scenario);
expect(macro.macros.test_tag.steps).to.be.eql(scenario.steps);
});
static createStep(macro) {
return new Step('When', `macro ${macro} is executed`);
}
}