1616 * specific language governing permissions and limitations
1717 * under the License.
1818 */
19- import { mockFatalError } from './subscribe_with_scope.test.mocks' ;
20-
2119import * as Rx from 'rxjs' ;
2220import { 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
7573it ( '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 ( `
8488Array [
8589 Array [
8690 [Error: foo bar],
@@ -90,12 +94,13 @@ Array [
9094} ) ;
9195
9296it ( '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 ( `
99104Array [
100105 Array [
101106 [Error: Uncaught error in subscribeWithScope(): foo
@@ -106,14 +111,20 @@ Array [
106111} ) ;
107112
108113it ( '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 ( `
117128Array [
118129 Array [
119130 [Error: foo],
@@ -123,25 +134,37 @@ Array [
123134} ) ;
124135
125136it ( '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
136153it ( '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 ( `
145168Array [
146169 Array [
147170 [Error: foo],
0 commit comments