Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Last active June 1, 2022 15:02
Show Gist options
  • Save NoriSte/7ce8dd459f8070e0a0f36ad798d70a3c to your computer and use it in GitHub Desktop.
Save NoriSte/7ce8dd459f8070e0a0f36ad798d70a3c to your computer and use it in GitHub Desktop.
Simple example of tests

Following Stately announcing the latest release of XState/test, I played a bit with the tool.

I have some doubts aobut the fact that XState/test does not allow (if I am not mistaken) to quickly isolate tests where each of them have their unique setup processes.

Here the gists I used to generate the screenshots I used in this series of tweets.

describe('Entity', () => {
describe('CREATE', () => {
before(() => {
// #1
// Delete the entity through API
});
it('Test', () => {
// #2
// CREATE the entity through UI
});
});
describe('MODIFY', () => {
before(() => {
// #3
// Create the entity through API (if does not exist)
// Cancel the modifications through API (if they exist)
});
it('Test', () => {
// #4
// MODIFY the entity through UI
});
});
describe('DELETE', () => {
before(() => {
// #5
// Create the entity through API (if does not exist)
});
it('Test', () => {
// #6
// DELETE the entity through UI
});
});
after(() => {
// #7
// Delete the entity through API (cleanup phase)
});
});
const machine = createTestMachine({
initial: 'visit',
states: {
visit: {
on: {
CREATE: 'entityCreated',
},
},
entityCreated: {
on: {
MODIFY: 'entityModified',
DELETE: 'entityDeleted',
},
},
entityModified: {},
entityDeleted: {},
},
});
const model = createTestModel(machine);
const paths = model.getPaths();
describe('Entity', () => {
paths.forEach(path => {
it(path.description, () => {
path.testSync(/* ... */);
// Delete the entity through API (cleanup phase)
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment