Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-donkeys-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"xstate-component-tree": patch
---

Fix .hasTag & .matches before interpreter is running
2 changes: 1 addition & 1 deletion src/component-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ComponentTree {
run : 0,

// Stored transition result, used to re-create the tree when a child transitions
state : false,
state : service.getSnapshot(),

// Walk results
tree : [],
Expand Down
16 changes: 11 additions & 5 deletions tests/api/observable.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as assert from "uvu/assert";
import { interpret } from "xstate";

import ComponentTree from "../../src/component-tree.js";

import describe from "../util/describe.js";
import { createTree } from "../util/trees.js";
Expand All @@ -9,13 +12,13 @@ import single from "./specimens/single.js";
describe("observable", (it) => {
it.after.each(treeTeardown);

it("should immediately call the callback", async (context) => {
const tree = context.tree = createTree(single);
it("should immediately call the callback", async () => {
const xct = new ComponentTree(interpret(single));

let calls = 0;
let out;

tree.builder.subscribe((result) => {
xct.subscribe((result) => {
++calls;

out = result;
Expand All @@ -30,6 +33,8 @@ describe("observable", (it) => {
assert.type(out.broadcast, "function");

assert.ok(out.hasTag("one"));

xct.teardown();
});

it("should call the callback whenever a run finishes", async (context) => {
Expand All @@ -56,10 +61,11 @@ describe("observable", (it) => {
assert.type(out.broadcast, "function");

tree.send("NEXT");

await tree();

assert.is(calls, 3);
assert.ok(out.hasTag("two"));
});

it("should return an unsubscriber", async (context) => {
Expand Down