From d44d4a1f811d4418c57aa00e58b743a8f05cf1cd Mon Sep 17 00:00:00 2001 From: oscar marina Date: Wed, 26 Jun 2024 14:46:01 +0200 Subject: [PATCH] [@xstate/lit] Defining onNext as an instance field --- jest.config.js | 3 +++ packages/xstate-lit/package.json | 4 ++-- packages/xstate-lit/src/UseMachine.ts | 5 ++--- scripts/jest-utils/setup.js | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/jest.config.js b/jest.config.js index 07edeb4e3c..6b7a915e47 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,9 @@ const { constants } = require('jest-config'); module.exports = { prettierPath: null, setupFilesAfterEnv: ['@xstate-repo/jest-utils/setup'], + transformIgnorePatterns: [ + 'node_modules/(?!(@open-wc|lit-html|lit-element|lit|@lit)/)' + ], transform: { [constants.DEFAULT_JS_PATTERN]: 'babel-jest', '^.+\\.vue$': '@vue/vue3-jest', diff --git a/packages/xstate-lit/package.json b/packages/xstate-lit/package.json index 81d42424be..8755885057 100644 --- a/packages/xstate-lit/package.json +++ b/packages/xstate-lit/package.json @@ -53,13 +53,13 @@ }, "peerDependencies": { "lit": "^3.1.2", - "xstate": "^5.9.1" + "xstate": "^5.14.0" }, "devDependencies": { "@open-wc/testing-helpers": "^3.0.0", "@testing-library/dom": "^9.3.4", "@types/jest": "^29.5.10", "lit": "^3.1.2", - "xstate": "5.9.1" + "xstate": "5.14.0" } } diff --git a/packages/xstate-lit/src/UseMachine.ts b/packages/xstate-lit/src/UseMachine.ts index 73a6c14110..bd5809ea68 100644 --- a/packages/xstate-lit/src/UseMachine.ts +++ b/packages/xstate-lit/src/UseMachine.ts @@ -36,7 +36,6 @@ export class UseMachine this.options = options; this.callback = callback; this.currentSnapshot = this.snapshot; - this.onNext = this.onNext.bind(this); (this.host = host).addController(this); } @@ -57,13 +56,13 @@ export class UseMachine this.subs.unsubscribe(); } - protected onNext(snapshot: SnapshotFrom) { + protected onNext = (snapshot: SnapshotFrom) => { if (this.currentSnapshot !== snapshot) { this.currentSnapshot = snapshot; this.callback?.(snapshot); this.host.requestUpdate(); } - } + }; private startService() { this.actorRef = createActor(this.machine, this.options); diff --git a/scripts/jest-utils/setup.js b/scripts/jest-utils/setup.js index 243803c1cc..5c2ef7b221 100644 --- a/scripts/jest-utils/setup.js +++ b/scripts/jest-utils/setup.js @@ -19,6 +19,15 @@ afterEach(() => { Object.keys(consoleSpies).forEach((method) => { const spy = consoleSpies[method]; + if (spy.mock.calls.length) { + spy.mock.calls = spy.mock.calls.filter( + (args) => + !args.includes( + 'Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.' + ) + ); + } + if (spy.mock.calls.length) { const calls = spy.mock.calls;