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 remove tag if presents on parent', () => {
const compiler = new RemoveDuplicates();
const element = {tags: [new Tag('@onFeature')]};
const parent = {tags: [new Tag('@onFeature')]};
compiler._filterTags(element, parent);
expect(element.tags).to.have.length(0);
expect(parent.tags).to.have.length(1);
});
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 return the correct iterator', () => {
const loop = new ForLoop();
const scenario = new Scenario('Scenario', 'Scenario name');
const tag = new Tag('@loop(4)');
scenario.tags.push(tag);
expect(loop.getIterationNumber(scenario)).to.eql(4);
});
});
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 not filter out non macro scenarios', () => {
const scenario = new Scenario();
const tag = new Tag('@notmacro');
scenario.tags.push(tag);
expect(macro.preFilterScenario(scenario)).to.be.undefined;
});
it('should not remove unique tags', () => {
const compiler = new RemoveDuplicates();
const element = {tags: [new Tag('@duplicate'), new Tag('@notDuplicate')]};
const parent = {tags: []};
compiler._filterTags(element, parent);
expect(element.tags).to.have.length(2);
expect(element.tags[0].name).to.equal('@duplicate');
expect(element.tags[1].name).to.equal('@notDuplicate');
});
it('should not remove unique tag if not present on parent', () => {
const compiler = new RemoveDuplicates();
const element = {tags: [new Tag('@onScenario')]};
const parent = {tags: [new Tag('@onFeature')]};
compiler._filterTags(element, parent);
expect(element.tags).to.have.length(1);
expect(element.tags[0].name).to.equal('@onScenario');
});
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 identify if a tag present on parent', () => {
const compiler = new RemoveDuplicates();
expect(compiler._hasTag({}, '@noTag'), 'identify if no tags field').to.be.false;
expect(compiler._hasTag({tags: []}, '@noTag'), 'identify if no tags at all').to.be.false;
expect(compiler._hasTag({tags: [new Tag('@found')]}, '@found'), 'identify if tag found').to.be.true;
expect(compiler._hasTag({tags: [new Tag('@notFound')]}, '@noTag'), 'identify if tag not found').to.be.false;
});
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);
});