Skip to content

Commit

Permalink
feat: added runner compatibility that does not globally expose the 'd…
Browse files Browse the repository at this point in the history
…escribe' and 'test' methods
  • Loading branch information
pplancq committed Apr 12, 2024
1 parent 94d1c05 commit f33a087
Show file tree
Hide file tree
Showing 11 changed files with 4,571 additions and 2,238 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from 'vitest';
import { StepDefinitions, loadFeatures, autoBindSteps } from '../../../../../src';
import { VendingMachine } from '../../../src/vending-machine';

export const vendingMachineSteps: StepDefinitions = ({ given, and, when, then }) => {
let vendingMachine: VendingMachine;

given(/^the vending machine has "(.*)" in stock$/, (itemName: string) => {
vendingMachine = new VendingMachine();
vendingMachine.stockItem(itemName, 1);
});

and('I have inserted the correct amount of money', () => {
vendingMachine.insertMoney(0.5);
});

when(/^I purchase "(.*)"$/, (itemName: string) => {
vendingMachine.dispenseItem(itemName);
});

then(/^my "(.*)" should be dispensed$/, (itemName: string) => {
const inventoryAmount = vendingMachine.items[itemName];
expect(inventoryAmount).toBe(0);
});
};

const features = loadFeatures('./examples/typescript/specs/features/auto-binding/**/*.feature');

autoBindSteps(features, [vendingMachineSteps]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { expect, beforeEach } from 'vitest';
import { loadFeature, defineFeature } from '../../../../src';
import { PasswordValidator } from '../../src/password-validator';

const feature = loadFeature('./examples/typescript/specs/features/basic-scenarios.feature');

defineFeature(feature, test => {
let passwordValidator = new PasswordValidator();
let accessGranted = false;

beforeEach(() => {
passwordValidator = new PasswordValidator();
});

test('Entering a correct password', ({ given, when, then }) => {
given('I have previously created a password', () => {
passwordValidator.setPassword('1234');
});

when('I enter my password correctly', () => {
accessGranted = passwordValidator.validatePassword('1234');
});

then('I should be granted access', () => {
expect(accessGranted).toBeTruthy();
});
});
});

0 comments on commit f33a087

Please sign in to comment.