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 provided iterator exceeds maximum', () => {
const loop = new ForLoop();
const scenario = new Scenario('Scenario', 'Scenario name');
const tag = new Tag('@loop(42)');
scenario.tags.push(tag);
expect(() => loop.getIterationNumber(scenario)).to.throw(Error);
});
it('should throw an error when a macro does not contain any steps', () => {
const scenario = new Scenario();
const tag = new Tag('@macro(test)');
scenario.tags.push(tag);
expect(() => macro.preFilterScenario(scenario)).to.throw(Error)
});
it('should process scenario names', () => {
const loop = new ForLoop();
const scenario = new Scenario('Scenario', 'Scenario name');
loop.getIterationNumber = sinon.stub().returns(3);
const result = loop.looper(scenario);
result.forEach((scenario, i) => {
expect(scenario.name).to.eql('Scenario name (' + (i + 1) + ')');
})
});
});
it('should repeat scenarios for the correct times', () => {
const loop = new ForLoop();
const scenario = new Scenario('Scenario', 'Scenario name');
loop.getIterationNumber = sinon.stub().returns(3);
const result = loop.looper(scenario);
expect(result).to.have.lengthOf(3);
expect(loop.getIterationNumber.calledWith(scenario)).to.be.true;
});
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 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 return 0 when there is no loop tag', () => {
const loop = new ForLoop();
const scenario = new Scenario('Scenario', 'Scenario name');
expect(loop.getIterationNumber(scenario)).to.eql(0);
});
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);
});