Skip to content

Commit

Permalink
Better test
Browse files Browse the repository at this point in the history
  • Loading branch information
farskid committed Nov 16, 2023
1 parent e344b46 commit 27ba800
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
5 changes: 1 addition & 4 deletions packages/machine-extractor/src/MachineExtractResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { choose } from 'xstate/lib/actions';
import { DeclarationType } from '.';
import { RecordOfArrays } from './RecordOfArrays';
import { ActionNode, ParsedChooseCondition } from './actions';
import {
extractObjectRecursively,
getObjectPropertyKey,
} from './extractAction';
import { getObjectPropertyKey } from './extractAction';
import { getMachineNodesFromFile } from './getMachineNodesFromFile';
import { TMachineCallExpression } from './machineCallExpression';
import { StateNodeReturn } from './stateNode';
Expand Down
52 changes: 41 additions & 11 deletions packages/machine-extractor/src/__tests__/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,56 @@ describe('Options', () => {
expect(t.isObjectMethod(node)).toBeTruthy();
});

it.only('Should extract complete machine options', () => {
it.only('Should extract implementations provided in machine options', () => {
const result = extractMachinesFromFile(`
createMachine({}, {
actions: {
test: assign({})
named: () => {},
namedAssign: assign({}),
namedRaise: raise({}),
namedLog: log(''),
namedSendTo: sendTo('', ''),
namedStop: stop('')
},
services: {},
guards: {},
delays: {}
services: {
'namedCallback': () => () => {}
},
actors: {
'namedPromise': () => Promise.resolve()
},
guards: {
namedGuard: () => {
return condition()
}
},
delays: {
namedDelay: () => 2000
}
})
`);

expect(result!.machines[0]!.getAllMachineOptions()).toMatchInlineSnapshot(`
{
"actions": "{
test: assign({})
}",
"actors": "{}",
"delays": "{}",
"guards": "{}",
"actions": {
"named": "() => {}",
"namedAssign": "assign({})",
"namedLog": "log('')",
"namedRaise": "raise({})",
"namedSendTo": "sendTo('', '')",
"namedStop": "stop('')",
},
"actors": {
"namedCallback": "() => () => {}",
"namedPromise": "() => Promise.resolve()",
},
"delays": {
"namedDelay": "() => 2000",
},
"guards": {
"namedGuard": "() => {
return condition()
}",
},
}
`);
});
Expand Down

0 comments on commit 27ba800

Please sign in to comment.