@@ -1246,6 +1246,48 @@ describe("sinonSpy.call", function () {
12461246 } ) ;
12471247 } ) ;
12481248
1249+ describe ( "constructor return" , function ( ) {
1250+ it ( "preserves returned object" , function ( ) {
1251+ const customReturn = { } ;
1252+ function CustomConstructor ( ) {
1253+ return customReturn ;
1254+ }
1255+ const SpiedCustomConstructor = sinonSpy ( CustomConstructor ) ;
1256+ const myInstance = new SpiedCustomConstructor ( ) ;
1257+
1258+ assert ( myInstance === customReturn ) ;
1259+ } ) ;
1260+
1261+ it ( "allows explicit returned object" , function ( ) {
1262+ const StubConstructor = sinonStub ( ) ;
1263+ const customReturn = { } ;
1264+ StubConstructor . returns ( customReturn ) ;
1265+ const myInstance = new StubConstructor ( ) ;
1266+
1267+ assert ( myInstance === customReturn ) ;
1268+ } ) ;
1269+
1270+ it ( "preserves returned function" , function ( ) {
1271+ function customReturn ( ) { } // eslint-disable-line no-empty-function
1272+ function CustomConstructor ( ) {
1273+ return customReturn ;
1274+ }
1275+ const SpiedCustomConstructor = sinonSpy ( CustomConstructor ) ;
1276+ const myInstance = new SpiedCustomConstructor ( ) ;
1277+
1278+ assert ( myInstance === customReturn ) ;
1279+ } ) ;
1280+
1281+ it ( "allows explicit returned function" , function ( ) {
1282+ const StubConstructor = sinonStub ( ) ;
1283+ function customReturn ( ) { } // eslint-disable-line no-empty-function
1284+ StubConstructor . returns ( customReturn ) ;
1285+ const myInstance = new StubConstructor ( ) ;
1286+
1287+ assert ( myInstance === customReturn ) ;
1288+ } ) ;
1289+ } ) ;
1290+
12491291 describe ( "functions" , function ( ) {
12501292 it ( "throws if spying on non-existent property" , function ( ) {
12511293 const myObj = { } ;
0 commit comments