Skip to content

Commit

Permalink
imp(core): 🎨 improve transition running status
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymichel committed Apr 29, 2019
1 parent b58e71d commit a7cb039
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ it('calls hooks', async () => {
});

it('catches error', async () => {
expect.assertions(3);
expect.assertions(2);
transitions.logger.error = jest.fn();

const appearError = () => {
Expand All @@ -93,7 +93,6 @@ it('catches error', async () => {
});
} catch (e) {
expect(e).toEqual(new Error('Transition error [appear]'));
expect(hooks.do).toHaveBeenLastCalledWith('appearCanceled', data, t);
expect(appearCanceled).toHaveBeenCalledTimes(1);
expect(transitions.isRunning).toBeFalsy();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ it('calls hooks (sync: true)', async () => {
});

it('catches error (leave, sync: false)', async () => {
expect.assertions(1);
expect.assertions(2);

const leaveError = () => {
throw new Error('test');
Expand All @@ -215,11 +215,12 @@ it('catches error (leave, sync: false)', async () => {
});
} catch (e) {
expect(e).toEqual(new Error('Transition error'));
expect(transitions.isRunning).toBeFalsy();
}
});

it('catches error (enter, sync: false)', async () => {
expect.assertions(1);
expect.assertions(2);

const enterError = () => {
throw new Error('test');
Expand All @@ -241,6 +242,7 @@ it('catches error (enter, sync: false)', async () => {
});
} catch (e) {
expect(e).toEqual(new Error('Transition error'));
expect(transitions.isRunning).toBeFalsy();
}
});

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/modules/Transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ export class Transitions {
await this.appear(data, t);
await this._doAsyncHook('afterAppear', data, t);
} catch (error) {
this._running = false;
this.logger.error(error);
await this._doAsyncHook('appearCanceled', data, t);
// TODO: use this hooks on `cancel()`
// await this._doAsyncHook('appearCanceled', data, t);
// TODO: should I throw or should I log…
throw new Error('Transition error [appear]');
}
Expand Down Expand Up @@ -230,6 +232,7 @@ export class Transitions {
// Remove current contaienr
this.remove(data);
} catch (error) {
this._running = false;
// TODO: use cases for cancellation
this.logger.error(error);

Expand Down

0 comments on commit a7cb039

Please sign in to comment.