From 81a3ac5314d25ffa587f079a01d36cf779e72698 Mon Sep 17 00:00:00 2001 From: nasdan Date: Thu, 21 Mar 2019 21:53:28 +0100 Subject: [PATCH 1/5] fix existings hoc specs --- src/__snapshots__/trackerHoc.test.js.snap | 51 +++++-- src/trackerHoc.js | 116 +++++++-------- src/trackerHoc.test.js | 165 ++++++++++------------ 3 files changed, 172 insertions(+), 160 deletions(-) diff --git a/src/__snapshots__/trackerHoc.test.js.snap b/src/__snapshots__/trackerHoc.test.js.snap index bc93922..19b2c3f 100644 --- a/src/__snapshots__/trackerHoc.test.js.snap +++ b/src/__snapshots__/trackerHoc.test.js.snap @@ -3,8 +3,13 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc 1`] = ` test @@ -15,11 +20,20 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals exports[`trackerHoc should render component with trackedPromiseInProgress equals false and area equals "testArea" when feeding area equals "testArea" 1`] = ` test @@ -31,8 +45,13 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 1`] = ` test @@ -46,9 +65,14 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals customProp="test" > test @@ -60,8 +84,13 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 1`] = ` test diff --git a/src/trackerHoc.js b/src/trackerHoc.js index 8117eb6..0881218 100644 --- a/src/trackerHoc.js +++ b/src/trackerHoc.js @@ -1,58 +1,58 @@ -import React, { Component } from 'react' -import { emitter, getCounter, promiseCounterUpdateEventId } from './trackPromise'; -import { defaultArea } from './constants'; - -// Props: -// config: { -// area: // can be null|undefined|'' (will default to DefaultArea) or area name -// delay: // Wait Xms to display the spinner (fast connections scenario avoid blinking) -// default value 0ms -// } -export const promiseTrackerHoc = (ComponentToWrap) => { - return class promiseTrackerComponent extends Component { - constructor(props) { - super(props); - - this.state = { - trackedPromiseInProgress: false, - area: { - area: (props.config && props.config.area) || defaultArea, - delay:(props.config && props.config.delay) || 0, - } - }; - } - - updateProgress(progress, afterUpdateCallback) { - this.setState({ trackedPromiseInProgress: progress }, afterUpdateCallback); - } - - subscribeToCounterUpdate() { - emitter.on(promiseCounterUpdateEventId, (anyPromiseInProgress, area) => { - if (this.state.area === area) { - this.updateProgress(anyPromiseInProgress); - } - }); - } - - componentDidMount() { - this.updateProgress( - Boolean(getCounter(this.state.area) > 0), - this.subscribeToCounterUpdate - ); - } - - componentWillUnmount() { - emitter.off(promiseCounterUpdateEventId); - } - - render() { - return ( - - ) - } - } -} +import React, { Component } from 'react' +import { emitter, getCounter, promiseCounterUpdateEventId } from './trackPromise'; +import { defaultArea } from './constants'; + +// Props: +// config: { +// area: // can be null|undefined|'' (will default to DefaultArea) or area name +// delay: // Wait Xms to display the spinner (fast connections scenario avoid blinking) +// default value 0ms +// } +export const promiseTrackerHoc = (ComponentToWrap) => { + return class promiseTrackerComponent extends Component { + constructor(props) { + super(props); + + this.state = { + promiseInProgress: false, + config: { + area: (props.config && props.config.area) || defaultArea, + delay: (props.config && props.config.delay) || 0, + } + }; + } + + updateProgress(progress, afterUpdateCallback) { + this.setState({ promiseInProgress: progress }, afterUpdateCallback); + } + + subscribeToCounterUpdate() { + emitter.on(promiseCounterUpdateEventId, (anyPromiseInProgress, area) => { + if (this.state.config.area === area) { + this.updateProgress(anyPromiseInProgress); + } + }); + } + + componentDidMount() { + this.updateProgress( + Boolean(getCounter(this.state.config.area) > 0), + this.subscribeToCounterUpdate + ); + } + + componentWillUnmount() { + emitter.off(promiseCounterUpdateEventId); + } + + render() { + return ( + + ) + } + } +} diff --git a/src/trackerHoc.test.js b/src/trackerHoc.test.js index 3e25a12..80de4e0 100644 --- a/src/trackerHoc.test.js +++ b/src/trackerHoc.test.js @@ -1,91 +1,74 @@ -import React from 'react'; -import { promiseTrackerHoc } from './trackerHoc'; -import * as trackPromiseAPI from './trackPromise'; - -describe('trackerHoc', () => { - it('should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc', () => { - // Arrange - const TestSpinnerComponent = (props) => test; - - // Act - const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); - - // Assert - const component = mount( - , - ); - - expect(component).toMatchSnapshot(); - }); - - it('should render component with trackedPromiseInProgress equals false, area equals "default-area" and customProp equals "test" when feeding customProp equals "test"', () => { - // Arrange - const TestSpinnerComponent = (props) => test; - - // Act - const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); - - // Assert - const component = mount( - , - ); - - expect(component).toMatchSnapshot(); - }); - - it('should render component with trackedPromiseInProgress equals false and area equals "testArea" when feeding area equals "testArea"', () => { - // Arrange - const TestSpinnerComponent = (props) => test; - - // Act - const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); - - // Assert - const component = mount( - , - ); - - expect(component).toMatchSnapshot(); - }); - - it('should render component with trackedPromiseInProgress equals false when counter is 0', () => { - // Arrange - const TestSpinnerComponent = (props) => test; - trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); - - // Act - const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); - - // Assert - const component = mount( - , - ); - - expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); - expect(component).toMatchSnapshot(); - }); - - it('should render component with trackedPromiseInProgress equals true when counter is 1', () => { - // Arrange - const TestSpinnerComponent = (props) => test; - trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); - - // Act - const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); - - // Assert - const component = mount( - , - ); - - expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); - expect(component).toMatchSnapshot(); - }); -}); +import React from "react"; +import { promiseTrackerHoc } from "./trackerHoc"; +import * as trackPromiseAPI from "./trackPromise"; + +describe("trackerHoc", () => { + it('should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc', () => { + // Arrange + const TestSpinnerComponent = props => test; + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(component).toMatchSnapshot(); + }); + + it('should render component with trackedPromiseInProgress equals false, area equals "default-area" and customProp equals "test" when feeding customProp equals "test"', () => { + // Arrange + const TestSpinnerComponent = props => test; + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(component).toMatchSnapshot(); + }); + + it('should render component with trackedPromiseInProgress equals false and area equals "testArea" when feeding area equals "testArea"', () => { + // Arrange + const TestSpinnerComponent = props => test; + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); +}); From fe82a6d8ccd978233f271e2c24f2fccd3a25e24f Mon Sep 17 00:00:00 2001 From: nasdan Date: Thu, 21 Mar 2019 22:16:50 +0100 Subject: [PATCH 2/5] fix typo --- src/trackerHook.js | 100 ++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/trackerHook.js b/src/trackerHook.js index 5e4854f..2ff5caa 100644 --- a/src/trackerHook.js +++ b/src/trackerHook.js @@ -1,50 +1,50 @@ -import React from "react"; -import { emitter, promiseCounterUpdateEventId } from "./trackPromise"; -import { defaultArea } from "./constants"; - -export const usePromiseTracker = (config = { area: defaultArea, delay: 0 }) => { - const [ - internalPromiseInProgress, - setInternalPromiseInProgress - ] = React.useState(false); - const [promiseInProgress, setPromiseInProgress] = React.useState(false); - const latestInternalPromiseInProgress = React.useRef( - internalPromiseInProgress - ); - - const notifiyPromiseInProgress = () => { - // Take into account delay parameter - setTimeout(() => { - // Check here ref to internalPromiseInProgress - if (latestInternalPromiseInProgress.current) { - setPromiseInProgress(true); - } - }, config.delay); - }; - - const updatePromiseTrackerStatus = (anyPromiseInProgress, areaAffected) => { - if (config.area === areaAffected) { - setInternalPromiseInProgress(anyPromiseInProgress); - if (!anyPromiseInProgress) { - setPromiseInProgress(false); - } else { - notifiyPromiseInProgress(); - } - } - }; - - React.useEffect(() => { - latestInternalPromiseInProgress.current = internalPromiseInProgress; - emitter.on(promiseCounterUpdateEventId, - (anyPromiseInProgress, areaAffected) => { - updatePromiseTrackerStatus(anyPromiseInProgress, areaAffected); - } - ); - - return () => { - emitter.off(promiseCounterUpdateEventId); - }; - }, []); - - return { promiseInProgress }; -}; +import React from "react"; +import { emitter, promiseCounterUpdateEventId } from "./trackPromise"; +import { defaultArea } from "./constants"; + +export const usePromiseTracker = (config = { area: defaultArea, delay: 0 }) => { + const [ + internalPromiseInProgress, + setInternalPromiseInProgress + ] = React.useState(false); + const [promiseInProgress, setPromiseInProgress] = React.useState(false); + const latestInternalPromiseInProgress = React.useRef( + internalPromiseInProgress + ); + + const notifyPromiseInProgress = () => { + // Take into account delay parameter + setTimeout(() => { + // Check here ref to internalPromiseInProgress + if (latestInternalPromiseInProgress.current) { + setPromiseInProgress(true); + } + }, config.delay); + }; + + const updatePromiseTrackerStatus = (anyPromiseInProgress, areaAffected) => { + if (config.area === areaAffected) { + setInternalPromiseInProgress(anyPromiseInProgress); + if (!anyPromiseInProgress) { + setPromiseInProgress(false); + } else { + notifyPromiseInProgress(); + } + } + }; + + React.useEffect(() => { + latestInternalPromiseInProgress.current = internalPromiseInProgress; + emitter.on(promiseCounterUpdateEventId, + (anyPromiseInProgress, areaAffected) => { + updatePromiseTrackerStatus(anyPromiseInProgress, areaAffected); + } + ); + + return () => { + emitter.off(promiseCounterUpdateEventId); + }; + }, []); + + return { promiseInProgress }; +}; From 3c8d32dd900619f0e34074cf65f00b4d44b6a63a Mon Sep 17 00:00:00 2001 From: nasdan Date: Thu, 21 Mar 2019 23:20:20 +0100 Subject: [PATCH 3/5] add specs simulating progress with event emitter --- src/__snapshots__/trackerHoc.test.js.snap | 146 +++++++++++++++++- src/trackerHoc.js | 37 +++-- src/trackerHoc.test.js | 171 +++++++++++++++++++++- 3 files changed, 343 insertions(+), 11 deletions(-) diff --git a/src/__snapshots__/trackerHoc.test.js.snap b/src/__snapshots__/trackerHoc.test.js.snap index 19b2c3f..5cd1551 100644 --- a/src/__snapshots__/trackerHoc.test.js.snap +++ b/src/__snapshots__/trackerHoc.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`trackerHoc should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc 1`] = ` +exports[`trackerHoc should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc without props 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false 1`] = ` + + + + test + + + +`; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false to different area 1`] = ` + + + + test + + + +`; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals true to different area 1`] = ` + + + + test + + + +`; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 1 and emit event with progress equals false 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false, area equals "default-area" and customProp equals "test" when feeding customProp equals "test" 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 0 and emit event with progress equals true 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 1`] = ` `; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals false to different area 1`] = ` + + + + test + + + +`; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true 1`] = ` + + + + test + + + +`; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true to different area 1`] = ` + + + + test + + + +`; diff --git a/src/trackerHoc.js b/src/trackerHoc.js index 0881218..f88622c 100644 --- a/src/trackerHoc.js +++ b/src/trackerHoc.js @@ -1,6 +1,10 @@ -import React, { Component } from 'react' -import { emitter, getCounter, promiseCounterUpdateEventId } from './trackPromise'; -import { defaultArea } from './constants'; +import React, { Component } from "react"; +import { + emitter, + getCounter, + promiseCounterUpdateEventId +} from "./trackPromise"; +import { defaultArea } from "./constants"; // Props: // config: { @@ -8,22 +12,37 @@ import { defaultArea } from './constants'; // delay: // Wait Xms to display the spinner (fast connections scenario avoid blinking) // default value 0ms // } -export const promiseTrackerHoc = (ComponentToWrap) => { +export const promiseTrackerHoc = ComponentToWrap => { return class promiseTrackerComponent extends Component { constructor(props) { super(props); this.state = { promiseInProgress: false, + internalPromiseInProgress: false, config: { area: (props.config && props.config.area) || defaultArea, - delay: (props.config && props.config.delay) || 0, + delay: (props.config && props.config.delay) || 0 } }; } + updateProgressWithDelay() { + setTimeout(() => { + this.setState({ + promiseInProgress: this.state.internalPromiseInProgress + }); + }, this.state.config.delay); + } + updateProgress(progress, afterUpdateCallback) { - this.setState({ promiseInProgress: progress }, afterUpdateCallback); + this.setState( + { internalPromiseInProgress: progress }, + afterUpdateCallback + ); + this.state.config.delay === 0 + ? this.setState({ promiseInProgress: progress }) + : this.updateProgressWithDelay(); } subscribeToCounterUpdate() { @@ -52,7 +71,7 @@ export const promiseTrackerHoc = (ComponentToWrap) => { config={this.state.config} promiseInProgress={this.state.promiseInProgress} /> - ) + ); } - } -} + }; +}; diff --git a/src/trackerHoc.test.js b/src/trackerHoc.test.js index 80de4e0..bb38484 100644 --- a/src/trackerHoc.test.js +++ b/src/trackerHoc.test.js @@ -1,9 +1,10 @@ import React from "react"; import { promiseTrackerHoc } from "./trackerHoc"; import * as trackPromiseAPI from "./trackPromise"; +import { defaultArea } from "./constants"; describe("trackerHoc", () => { - it('should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc', () => { + it('should render component with trackedPromiseInProgress equals false and area equals "default-area" when render promiseTrackerHoc without props', () => { // Arrange const TestSpinnerComponent = props => test; @@ -57,6 +58,90 @@ describe("trackerHoc", () => { expect(component).toMatchSnapshot(); }); + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = false; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false to different area", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = false; + const area = 'otherArea'; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 0 and emit event with progress equals true", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = true; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals true to different area", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = true; + const area = 'otherArea'; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + it("should render component with trackedPromiseInProgress equals true when counter is 1", () => { // Arrange const TestSpinnerComponent = props => test; @@ -71,4 +156,88 @@ describe("trackerHoc", () => { expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); expect(component).toMatchSnapshot(); }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = true; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true to different area", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = true; + const area = 'otherArea'; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 1 and emit event with progress equals false", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = false; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals false to different area", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = false; + const area = 'otherArea'; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); }); From 2b74aee8af8c7a92c33ee5ceb1bc179b83bdc12f Mon Sep 17 00:00:00 2001 From: nasdan Date: Fri, 22 Mar 2019 10:40:52 +0100 Subject: [PATCH 4/5] Added delay specs. not working yet --- .vscode/launch.json | 50 ++-- src/__snapshots__/trackerHoc.test.js.snap | 265 ++++++++++++++++++++++ src/trackerHoc.test.js | 224 +++++++++++++++++- 3 files changed, 518 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4974b0e..bbe6b10 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,33 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Jest single run", - "program": "${workspaceRoot}/node_modules/jest/bin/jest.js", - "args": [ - "--verbose", - "-i" - ], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen" - }, - ] -} + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest single run", + "program": "${workspaceRoot}/node_modules/jest/bin/jest.js", + "args": [ + "--verbose", + "-i", + "--no-cache" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Jest watch run", + "program": "${workspaceRoot}/node_modules/jest/bin/jest.js", + "args": [ + "--verbose", + "-i", + "--no-cache", + "--watchAll" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/src/__snapshots__/trackerHoc.test.js.snap b/src/__snapshots__/trackerHoc.test.js.snap index 5cd1551..e190557 100644 --- a/src/__snapshots__/trackerHoc.test.js.snap +++ b/src/__snapshots__/trackerHoc.test.js.snap @@ -42,6 +42,31 @@ exports[`trackerHoc should render component with trackedPromiseInProgress equals `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false and area equals "testArea" when feeding area equals "testArea" and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false to different area 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false to different area and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals true to different area 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals true to different area and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 1 and emit event with progress equals false 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals false when counter is 1 and emit event with progress equals false and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals false, area equals "default-area" and customProp equals "test" when feeding customProp equals "test" 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 0 and emit event with progress equals true and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals false to different area 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals false to different area and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true 1`] = ` `; +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true and delay equals 300 1`] = ` + + + + test + + + +`; + exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true to different area 1`] = ` `; + +exports[`trackerHoc should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true to different area and delay equals 300 1`] = ` + + + + test + + + +`; diff --git a/src/trackerHoc.test.js b/src/trackerHoc.test.js index bb38484..7aa2447 100644 --- a/src/trackerHoc.test.js +++ b/src/trackerHoc.test.js @@ -85,7 +85,7 @@ describe("trackerHoc", () => { trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); const progress = false; - const area = 'otherArea'; + const area = "otherArea"; const emitterStub = jest .spyOn(trackPromiseAPI.emitter, "on") .mockImplementation((id, callback) => callback(progress, area)); @@ -127,7 +127,7 @@ describe("trackerHoc", () => { trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); const progress = true; - const area = 'otherArea'; + const area = "otherArea"; const emitterStub = jest .spyOn(trackPromiseAPI.emitter, "on") .mockImplementation((id, callback) => callback(progress, area)); @@ -184,7 +184,7 @@ describe("trackerHoc", () => { trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); const progress = true; - const area = 'otherArea'; + const area = "otherArea"; const emitterStub = jest .spyOn(trackPromiseAPI.emitter, "on") .mockImplementation((id, callback) => callback(progress, area)); @@ -226,7 +226,7 @@ describe("trackerHoc", () => { trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); const progress = false; - const area = 'otherArea'; + const area = "otherArea"; const emitterStub = jest .spyOn(trackPromiseAPI.emitter, "on") .mockImplementation((id, callback) => callback(progress, area)); @@ -240,4 +240,220 @@ describe("trackerHoc", () => { expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); expect(component).toMatchSnapshot(); }); + + it('should render component with trackedPromiseInProgress equals false and area equals "testArea" when feeding area equals "testArea" and delay equals 300', () => { + // Arrange + const TestSpinnerComponent = props => test; + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount( + + ); + + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = false; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals false to different area and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = false; + const area = "otherArea"; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it.only("should render component with trackedPromiseInProgress equals true when counter is 0 and emit event with progress equals true and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = true; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + const setTimeoutStub = jest + .spyOn(window, "setTimeout") + .mockImplementation((callback) => callback()); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 0 and emit event with progress equals true to different area and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 0); + + const progress = true; + const area = "otherArea"; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = true; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals true to different area and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = true; + const area = "otherArea"; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals false when counter is 1 and emit event with progress equals false and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = false; + const area = defaultArea; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); + + it("should render component with trackedPromiseInProgress equals true when counter is 1 and emit event with progress equals false to different area and delay equals 300", () => { + // Arrange + const TestSpinnerComponent = props => test; + trackPromiseAPI.getCounter = jest.fn().mockImplementation(() => 1); + + const progress = false; + const area = "otherArea"; + const emitterStub = jest + .spyOn(trackPromiseAPI.emitter, "on") + .mockImplementation((id, callback) => callback(progress, area)); + + // Act + const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); + + // Assert + const component = mount(); + + expect(trackPromiseAPI.getCounter).toHaveBeenCalled(); + expect(component).toMatchSnapshot(); + }); }); From 189bbed3caf71b8dc0b0cafea807538e3702c48b Mon Sep 17 00:00:00 2001 From: nasdan Date: Fri, 22 Mar 2019 10:43:13 +0100 Subject: [PATCH 5/5] Fix autoclrf --- src/trackPromise.js | 18 ++--- src/trackPromise.test.js | 161 ++++++++++++++++++++++++++++----------- src/trackerHoc.test.js | 2 +- src/trackerHook.js | 3 +- 4 files changed, 129 insertions(+), 55 deletions(-) diff --git a/src/trackPromise.js b/src/trackPromise.js index 123195d..4a6ae4f 100644 --- a/src/trackPromise.js +++ b/src/trackPromise.js @@ -1,14 +1,14 @@ -import { Emitter } from './tinyEmmiter'; -import { defaultArea } from './constants'; +import { Emitter } from "./tinyEmmiter"; +import { defaultArea } from "./constants"; export const emitter = new Emitter(); -export const promiseCounterUpdateEventId = 'promise-counter-update'; +export const promiseCounterUpdateEventId = "promise-counter-update"; let counter = { - [defaultArea]: 0, + [defaultArea]: 0 }; -export const getCounter = (area) => counter[area]; +export const getCounter = area => counter[area]; export const trackPromise = (promise, area) => { area = area || defaultArea; @@ -23,7 +23,7 @@ export const trackPromise = (promise, area) => { return promise; }; -const incrementCounter = (area) => { +const incrementCounter = area => { if (Boolean(counter[area])) { counter[area]++; } else { @@ -31,15 +31,15 @@ const incrementCounter = (area) => { } }; -const anyPromiseInProgress = (area) => (counter[area] > 0); +const anyPromiseInProgress = area => counter[area] > 0; -const decrementPromiseCounter = (area) => { +const decrementPromiseCounter = area => { decrementCounter(area); const promiseInProgress = anyPromiseInProgress(); emitter.emit(promiseCounterUpdateEventId, promiseInProgress, area); }; -const decrementCounter = (area) => { +const decrementCounter = area => { counter[area]--; }; diff --git a/src/trackPromise.test.js b/src/trackPromise.test.js index d939938..e122a9f 100644 --- a/src/trackPromise.test.js +++ b/src/trackPromise.test.js @@ -1,9 +1,9 @@ -import { trackPromise, emitter } from './trackPromise'; -import { defaultArea } from './constants'; +import { trackPromise, emitter } from "./trackPromise"; +import { defaultArea } from "./constants"; -describe('trackPromise', () => { - describe('using default area', () => { - it('On Initial case, promise fired, promise emitter.emit is called', () => { +describe("trackPromise", () => { + describe("using default area", () => { + it("On Initial case, promise fired, promise emitter.emit is called", () => { // Arrange emitter.emit = jest.fn(); @@ -15,10 +15,14 @@ describe('trackPromise', () => { // Assert expect(emitter.emit).toHaveBeenCalledTimes(1); - expect(emitter.emit).toHaveBeenCalledWith('promise-counter-update', true, defaultArea); + expect(emitter.emit).toHaveBeenCalledWith( + "promise-counter-update", + true, + defaultArea + ); }); - it('Promise tracked, we got resolve, check that emit is called 2 times', (done) => { + it("Promise tracked, we got resolve, check that emit is called 2 times", done => { // Arrange emitter.emit = jest.fn(); @@ -31,14 +35,24 @@ describe('trackPromise', () => { myPromise.then(() => { expect(emitter.emit).toHaveBeenCalledTimes(2); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'promise-counter-update', true, defaultArea); - - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'promise-counter-update', false, defaultArea); + expect(emitter.emit).toHaveBeenNthCalledWith( + 1, + "promise-counter-update", + true, + defaultArea + ); + + expect(emitter.emit).toHaveBeenNthCalledWith( + 2, + "promise-counter-update", + false, + defaultArea + ); done(); }); }); - it('Promise tracked, we got fail, check that emit is called 2 times', (done) => { + it("Promise tracked, we got fail, check that emit is called 2 times", done => { // Arrange emitter.emit = jest.fn(); @@ -51,16 +65,25 @@ describe('trackPromise', () => { myPromise.catch(() => { expect(emitter.emit).toHaveBeenCalledTimes(2); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'promise-counter-update', true, defaultArea); - - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'promise-counter-update', false, defaultArea); + expect(emitter.emit).toHaveBeenNthCalledWith( + 1, + "promise-counter-update", + true, + defaultArea + ); + + expect(emitter.emit).toHaveBeenNthCalledWith( + 2, + "promise-counter-update", + false, + defaultArea + ); done(); }); }); - // Pending promise failed - it('Two Promises tracked, we got resolve on both, check that emit is called 4 times', (done) => { + it("Two Promises tracked, we got resolve on both, check that emit is called 4 times", done => { // Arrange emitter.emit = jest.fn(); @@ -76,19 +99,39 @@ describe('trackPromise', () => { Promise.all(promises).then(() => { expect(emitter.emit).toHaveBeenCalledTimes(4); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'promise-counter-update', true, defaultArea); - - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'promise-counter-update', true, defaultArea); - - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'promise-counter-update', false, defaultArea); - - expect(emitter.emit).toHaveBeenNthCalledWith(4, 'promise-counter-update', false, defaultArea); + expect(emitter.emit).toHaveBeenNthCalledWith( + 1, + "promise-counter-update", + true, + defaultArea + ); + + expect(emitter.emit).toHaveBeenNthCalledWith( + 2, + "promise-counter-update", + true, + defaultArea + ); + + expect(emitter.emit).toHaveBeenNthCalledWith( + 3, + "promise-counter-update", + false, + defaultArea + ); + + expect(emitter.emit).toHaveBeenNthCalledWith( + 4, + "promise-counter-update", + false, + defaultArea + ); done(); }); }); // Promise chaining working properly. - it('Promise returned must handle transparently the result when resolved', (done) => { + it("Promise returned must handle transparently the result when resolved", done => { // Arrange const expectedPromiseResult = "promise result"; const promise = Promise.resolve(expectedPromiseResult); @@ -97,16 +140,15 @@ describe('trackPromise', () => { const trackedPromise = trackPromise(promise); // Assert - trackedPromise.then((trackedPromiseResult) => { + trackedPromise.then(trackedPromiseResult => { expect(trackedPromiseResult).toEqual(expectedPromiseResult); done(); }); }); - }); - describe('using custom area', () => { - it('should call emitter.emit one time when feeding promise and area equals undefined', () => { + describe("using custom area", () => { + it("should call emitter.emit one time when feeding promise and area equals undefined", () => { // Arrange emitter.emit = jest.fn(); @@ -118,10 +160,14 @@ describe('trackPromise', () => { // Assert expect(emitter.emit).toHaveBeenCalledTimes(1); - expect(emitter.emit).toHaveBeenCalledWith('promise-counter-update', true, defaultArea); + expect(emitter.emit).toHaveBeenCalledWith( + "promise-counter-update", + true, + defaultArea + ); }); - it('should call emitter.emit one time when feeding promise and area equals null', () => { + it("should call emitter.emit one time when feeding promise and area equals null", () => { // Arrange emitter.emit = jest.fn(); @@ -133,32 +179,40 @@ describe('trackPromise', () => { // Assert expect(emitter.emit).toHaveBeenCalledTimes(1); - expect(emitter.emit).toHaveBeenCalledWith('promise-counter-update', true, defaultArea); + expect(emitter.emit).toHaveBeenCalledWith( + "promise-counter-update", + true, + defaultArea + ); }); - it('should call emitter.emit one time when feeding promise and area equals testArea', () => { + it("should call emitter.emit one time when feeding promise and area equals testArea", () => { // Arrange emitter.emit = jest.fn(); const myPromise = Promise.resolve(); - const area = 'testArea'; + const area = "testArea"; // Act trackPromise(myPromise, area); // Assert expect(emitter.emit).toHaveBeenCalledTimes(1); - expect(emitter.emit).toHaveBeenCalledWith('promise-counter-update', true, 'testArea'); + expect(emitter.emit).toHaveBeenCalledWith( + "promise-counter-update", + true, + "testArea" + ); }); - it('should call emitter.emit two times when feeding two promises in same area', () => { + it("should call emitter.emit two times when feeding two promises in same area", () => { // Arrange emitter.emit = jest.fn(); const myPromise1 = Promise.resolve(); const myPromise2 = Promise.resolve(); - const area = 'testArea'; + const area = "testArea"; // Act trackPromise(myPromise1, area); @@ -166,19 +220,29 @@ describe('trackPromise', () => { // Assert expect(emitter.emit).toHaveBeenCalledTimes(2); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'promise-counter-update', true, 'testArea'); - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'promise-counter-update', true, 'testArea'); + expect(emitter.emit).toHaveBeenNthCalledWith( + 1, + "promise-counter-update", + true, + "testArea" + ); + expect(emitter.emit).toHaveBeenNthCalledWith( + 2, + "promise-counter-update", + true, + "testArea" + ); }); - it('should call emitter.emit two times when feeding two promises in different areas', () => { + it("should call emitter.emit two times when feeding two promises in different areas", () => { // Arrange emitter.emit = jest.fn(); const myPromise1 = Promise.resolve(); const myPromise2 = Promise.resolve(); - const area1 = 'testArea1'; - const area2 = 'testArea2'; + const area1 = "testArea1"; + const area2 = "testArea2"; // Act trackPromise(myPromise1, area1); @@ -186,9 +250,18 @@ describe('trackPromise', () => { // Assert expect(emitter.emit).toHaveBeenCalledTimes(2); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'promise-counter-update', true, 'testArea1'); - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'promise-counter-update', true, 'testArea2'); + expect(emitter.emit).toHaveBeenNthCalledWith( + 1, + "promise-counter-update", + true, + "testArea1" + ); + expect(emitter.emit).toHaveBeenNthCalledWith( + 2, + "promise-counter-update", + true, + "testArea2" + ); }); }); }); - diff --git a/src/trackerHoc.test.js b/src/trackerHoc.test.js index 7aa2447..01a48f9 100644 --- a/src/trackerHoc.test.js +++ b/src/trackerHoc.test.js @@ -325,7 +325,7 @@ describe("trackerHoc", () => { .mockImplementation((id, callback) => callback(progress, area)); const setTimeoutStub = jest .spyOn(window, "setTimeout") - .mockImplementation((callback) => callback()); + .mockImplementation(callback => callback()); // Act const TrackedComponent = promiseTrackerHoc(TestSpinnerComponent); diff --git a/src/trackerHook.js b/src/trackerHook.js index 2ff5caa..3cb89e8 100644 --- a/src/trackerHook.js +++ b/src/trackerHook.js @@ -35,7 +35,8 @@ export const usePromiseTracker = (config = { area: defaultArea, delay: 0 }) => { React.useEffect(() => { latestInternalPromiseInProgress.current = internalPromiseInProgress; - emitter.on(promiseCounterUpdateEventId, + emitter.on( + promiseCounterUpdateEventId, (anyPromiseInProgress, areaAffected) => { updatePromiseTrackerStatus(anyPromiseInProgress, areaAffected); }