Skip to content

Commit

Permalink
fixed it without casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Nov 28, 2024
1 parent 05c87c9 commit b798338
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/xstate-inspect/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function inspect(options: ServerInspectorOptions): Inspector {
return;
}

const jsonMessage = JSON.parse(String(data as unknown));
const jsonMessage = JSON.parse(String(data));

Check failure on line 76 in packages/xstate-inspect/src/server.ts

View workflow job for this annotation

GitHub Actions / build

'data' may use Object's default stringification format ('[object Object]') when stringified
inspectService.send({
...jsonMessage,
client
Expand Down
62 changes: 32 additions & 30 deletions packages/xstate-react/test/useActor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
assign,
createActor,
createMachine,
raise
raise,
setup
} from 'xstate';
import { fromCallback, fromObservable, fromPromise } from 'xstate/actors';
import { useActor, useSelector } from '../src/index.ts';
Expand Down Expand Up @@ -664,37 +665,34 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
it('should be able to use a delay provided outside of React', () => {
jest.useFakeTimers();

const machine = createMachine(
{
initial: 'a',
states: {
a: {
on: {
EV: 'b'
}
},
b: {
after: {
myDelay: 'c'
}
},
c: {}
const machine = setup({
delays: {
myDelay: () => {
return 300;
}
},
{
delays: {
myDelay: () => {
return 300;
}
}).createMachine({
initial: 'a',
states: {
a: {
on: {
EV: 'b'
}
}
},
b: {
after: {
myDelay: 'c'
}
},
c: {}
}
);
});

const App = () => {
const [state, send] = useActor(machine);
return (
<>
<div data-testid="result">{state.value as string}</div>
<div data-testid="result">{state.value}</div>
<button onClick={() => send({ type: 'EV' })} />
</>
);
Expand All @@ -715,7 +713,11 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
});

it('should not use stale data in a guard', () => {
const machine = createMachine({
const machine = setup({
guards: {
isAwesome: () => false
}
}).createMachine({
initial: 'a',
states: {
a: {
Expand All @@ -740,7 +742,7 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
);
return (
<>
<div data-testid="result">{state.value as string}</div>
<div data-testid="result">{state.value}</div>
<button onClick={() => send({ type: 'EV' })} />
</>
);
Expand Down Expand Up @@ -784,7 +786,7 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
});

it('child component should be able to send an event to a parent immediately in an effect', () => {
const machine = createMachine({
const machine = setup({}).createMachine({
types: {} as {
events: {
type: 'FINISH';
Expand Down Expand Up @@ -815,7 +817,7 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
return (
<>
<ChildTest send={send} />
{state.value as string}
{state.value}
</>
);
};
Expand Down Expand Up @@ -1030,7 +1032,7 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {
});

it('should execute a delayed transition of the initial state', async () => {
const machine = createMachine({
const machine = setup({}).createMachine({
initial: 'one',
states: {
one: {
Expand All @@ -1044,7 +1046,7 @@ describeEachReactMode('useActor (%s)', ({ suiteKey, render }) => {

const App = () => {
const [state] = useActor(machine);
return <>{state.value as string}</>;
return <>{state.value}</>;
};

const { container } = render(<App />);
Expand Down
12 changes: 7 additions & 5 deletions packages/xstate-react/test/useSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
StateFrom,
Snapshot,
TransitionSnapshot,
AnyEventObject
AnyEventObject,
setup
} from 'xstate';
import {
shallowEqual,
Expand Down Expand Up @@ -647,7 +648,7 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => {
});

it('should work with initially deferred actors spawned in lazy context', () => {
const childMachine = createMachine({
const childMachine = setup({}).createMachine({
initial: 'one',
states: {
one: {
Expand All @@ -657,10 +658,11 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => {
}
});

const machine = createMachine({
const machine = setup({
types: {} as {
context: { ref: ActorRefFrom<typeof childMachine> };
},
}
}).createMachine({
context: ({ spawn }) => ({
ref: spawn(childMachine)
}),
Expand All @@ -682,7 +684,7 @@ describeEachReactMode('useSelector (%s)', ({ suiteKey, render }) => {

return (
<>
<div data-testid="child-state">{childState.value as string}</div>
<div data-testid="child-state">{childState.value}</div>
<button
data-testid="child-send"
onClick={() => childRef.send({ type: 'NEXT' })}
Expand Down

0 comments on commit b798338

Please sign in to comment.