Fixtures
Fixtures in Autometa are classes decorated with @Fixture
. Fixtures
can be defined in the App
, where they will be automatically
injected for each running scenario.
Fixtures can also reference each other in their constructors, which will also be injected.
Assume we have two fixtures, HttpClient
, and MyApiClient
, where
HTTPClient handles basic HTTP calls and MyApiClient is a wrapper
over HTTPClient that defines the API Services endpoints.
- HTTPClient
- MyApiClient
- MyApp
- Steps
import { Fixture } from "@autometa/cucumber-runner";
@Fixture
export class HTTPClient {
async get(url: string, queryString: unknown) {}
async post(url: string, body: unknown) {}
async put(url: string, body: unknown) {}
async del(url: string, body: unknown) {}
}
import { Fixture } from "@autometa/cucumber-runner";
@Fixture
export class MyApiClient {
url: string;
constructor(readonly http: HTTPClient) {
this.url = process.env.API_URL;
}
getWidget(id: string) {
return this.http.get(`${this.url}/widget/${id}`);
}
async createWidget() {}
async updateWidget() {}
}
import { Fixture, Persistent } from "@autometa/cucumber-runner";
@Fixture
@Persistent
export class MyApp {
constructor(readonly world: World, readonly api: MyApiClient) {}
}
import { When } from "@autometa/cucumber-runner";
When("they get a widget", async ({ world, api }: App) => {
world.getWidgetResponse = await api.getWidget();
});