@@ -4,6 +4,7 @@ import { click, render } from '@ember/test-helpers';
4
4
import { hbs } from 'ember-cli-htmlbars' ;
5
5
import Component from '@ember/component' ;
6
6
import { task } from 'ember-concurrency' ;
7
+ import sinon from 'sinon' ;
7
8
8
9
module ( 'Integration | helpers | perform' , function ( hooks ) {
9
10
setupRenderingTest ( hooks ) ;
@@ -35,4 +36,66 @@ module('Integration | helpers | perform', function (hooks) {
35
36
36
37
assert . ok ( true ) ;
37
38
} ) ;
39
+
40
+ test ( 'can pass onError=null to have it swallow errors thrown from task' , async function ( assert ) {
41
+ assert . expect ( 1 ) ;
42
+
43
+ this . owner . register (
44
+ 'component:test-swallow-error' ,
45
+ Component . extend ( {
46
+ errorGeneratingTask : task ( function * ( ) {
47
+ throw new Error ( 'You should not see me!' ) ;
48
+ } ) ,
49
+ } )
50
+ ) ;
51
+
52
+ this . owner . register (
53
+ 'template:components/test-swallow-error' ,
54
+ hbs `
55
+ <button {{on 'click' (perform this.errorGeneratingTask onError=null)}}>
56
+ I create an error!
57
+ </button>
58
+ `
59
+ ) ;
60
+
61
+ await render ( hbs `<TestSwallowError />` ) ;
62
+
63
+ await click ( 'button' ) ;
64
+
65
+ assert . ok ( true ) ;
66
+ } ) ;
67
+
68
+ test ( 'can pass onError=someFn to have it call someFn(e)' , async function ( assert ) {
69
+ assert . expect ( 2 ) ;
70
+
71
+ let error = null ;
72
+
73
+ this . owner . register (
74
+ 'component:test-swallow-error' ,
75
+ Component . extend ( {
76
+ errorGeneratingTask : task ( function * ( ) {
77
+ throw new Error ( 'You should not see me!' ) ;
78
+ } ) ,
79
+ errorReport ( e ) {
80
+ error = e ;
81
+ } ,
82
+ } )
83
+ ) ;
84
+
85
+ this . owner . register (
86
+ 'template:components/test-swallow-error' ,
87
+ hbs `
88
+ <button {{on 'click' (perform this.errorGeneratingTask onError=this.errorReport)}}>
89
+ I create an error!
90
+ </button>
91
+ `
92
+ ) ;
93
+
94
+ await render ( hbs `<TestSwallowError />` ) ;
95
+
96
+ await click ( 'button' ) ;
97
+
98
+ assert . ok ( true ) ;
99
+ assert . ok ( error instanceof Error ) ;
100
+ } ) ;
38
101
} ) ;
0 commit comments