Skip to content

Commit b3101e9

Browse files
committed
Fix jest tests
1 parent 2651f01 commit b3101e9

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

src/legacy/ui/public/timefilter/setup_router.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import { registerTimefilterWithGlobalState } from './setup_router';
2020

21-
jest.mock('ui/utils/subscribe_with_scope', () => ({
21+
jest.mock('../../../../plugins/kibana_legacy/public', () => ({
2222
subscribeWithScope: jest.fn(),
2323
}));
2424

src/plugins/kibana_legacy/public/angular/subscribe_with_scope.test.mocks.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/plugins/kibana_legacy/public/angular/subscribe_with_scope.test.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { mockFatalError } from './subscribe_with_scope.test.mocks';
20-
2119
import * as Rx from 'rxjs';
2220
import { subscribeWithScope } from './subscribe_with_scope';
2321

@@ -73,14 +71,20 @@ it('calls observer.next() if already in a digest cycle, wraps in $scope.$apply i
7371
});
7472

7573
it('reports fatalError if observer.next() throws', () => {
74+
const fatalError = jest.fn();
7675
const $scope = new Scope();
77-
subscribeWithScope($scope as any, Rx.of(undefined), {
78-
next() {
79-
throw new Error('foo bar');
76+
subscribeWithScope(
77+
$scope as any,
78+
Rx.of(undefined),
79+
{
80+
next() {
81+
throw new Error('foo bar');
82+
},
8083
},
81-
});
84+
fatalError
85+
);
8286

83-
expect(mockFatalError.mock.calls).toMatchInlineSnapshot(`
87+
expect(fatalError.mock.calls).toMatchInlineSnapshot(`
8488
Array [
8589
Array [
8690
[Error: foo bar],
@@ -90,12 +94,13 @@ Array [
9094
});
9195

9296
it('reports fatal error if observer.error is not defined and observable errors', () => {
97+
const fatalError = jest.fn();
9398
const $scope = new Scope();
9499
const error = new Error('foo');
95100
error.stack = `${error.message}\n---stack trace ---`;
96-
subscribeWithScope($scope as any, Rx.throwError(error));
101+
subscribeWithScope($scope as any, Rx.throwError(error), undefined, fatalError);
97102

98-
expect(mockFatalError.mock.calls).toMatchInlineSnapshot(`
103+
expect(fatalError.mock.calls).toMatchInlineSnapshot(`
99104
Array [
100105
Array [
101106
[Error: Uncaught error in subscribeWithScope(): foo
@@ -106,14 +111,20 @@ Array [
106111
});
107112

108113
it('reports fatal error if observer.error throws', () => {
114+
const fatalError = jest.fn();
109115
const $scope = new Scope();
110-
subscribeWithScope($scope as any, Rx.throwError(new Error('foo')), {
111-
error: () => {
112-
throw new Error('foo');
116+
subscribeWithScope(
117+
$scope as any,
118+
Rx.throwError(new Error('foo')),
119+
{
120+
error: () => {
121+
throw new Error('foo');
122+
},
113123
},
114-
});
124+
fatalError
125+
);
115126

116-
expect(mockFatalError.mock.calls).toMatchInlineSnapshot(`
127+
expect(fatalError.mock.calls).toMatchInlineSnapshot(`
117128
Array [
118129
Array [
119130
[Error: foo],
@@ -123,25 +134,37 @@ Array [
123134
});
124135

125136
it('does not report fatal error if observer.error handles the error', () => {
137+
const fatalError = jest.fn();
126138
const $scope = new Scope();
127-
subscribeWithScope($scope as any, Rx.throwError(new Error('foo')), {
128-
error: () => {
129-
// noop, swallow error
139+
subscribeWithScope(
140+
$scope as any,
141+
Rx.throwError(new Error('foo')),
142+
{
143+
error: () => {
144+
// noop, swallow error
145+
},
130146
},
131-
});
147+
fatalError
148+
);
132149

133-
expect(mockFatalError.mock.calls).toEqual([]);
150+
expect(fatalError.mock.calls).toEqual([]);
134151
});
135152

136153
it('reports fatal error if observer.complete throws', () => {
154+
const fatalError = jest.fn();
137155
const $scope = new Scope();
138-
subscribeWithScope($scope as any, Rx.EMPTY, {
139-
complete: () => {
140-
throw new Error('foo');
156+
subscribeWithScope(
157+
$scope as any,
158+
Rx.EMPTY,
159+
{
160+
complete: () => {
161+
throw new Error('foo');
162+
},
141163
},
142-
});
164+
fatalError
165+
);
143166

144-
expect(mockFatalError.mock.calls).toMatchInlineSnapshot(`
167+
expect(fatalError.mock.calls).toMatchInlineSnapshot(`
145168
Array [
146169
Array [
147170
[Error: foo],

0 commit comments

Comments
 (0)