@@ -15,15 +15,22 @@ jest.dontMock('../ParseError');
1515jest . dontMock ( '../ParseObject' ) ;
1616jest . dontMock ( '../ParseQuery' ) ;
1717jest . dontMock ( '../Push' ) ;
18+ jest . dontMock ( '../parseDate' ) ;
19+ jest . dontMock ( '../ObjectStateMutations' ) ;
20+ jest . dontMock ( '../SingleInstanceStateController' ) ;
21+ jest . dontMock ( '../UniqueInstanceStateController' ) ;
1822
1923const Cloud = require ( '../Cloud' ) ;
2024const CoreManager = require ( '../CoreManager' ) ;
2125const Push = require ( '../Push' ) ;
26+ const ParseObject = require ( '../ParseObject' ) . default ;
2227
2328const defaultController = CoreManager . getCloudController ( ) ;
2429
2530describe ( 'Cloud' , ( ) => {
2631 beforeEach ( ( ) => {
32+ ParseObject . enableSingleInstance ( ) ;
33+
2734 const run = jest . fn ( ) ;
2835 const getJobsData = jest . fn ( ) ;
2936 const startJob = jest . fn ( ) ;
@@ -216,6 +223,48 @@ describe('CloudController', () => {
216223 } ) ;
217224 } ) ;
218225
226+ it ( 'run same function twice with different responses' , async ( ) => {
227+ const request = jest . fn ( ) ;
228+ request . mockReturnValue (
229+ Promise . resolve ( {
230+ success : true ,
231+ result : {
232+ objectId : 'abc123' ,
233+ className : 'Item' ,
234+ __type : 'Object' ,
235+ createdAt : '2015-01-01T00:00:00.000Z' ,
236+ updatedAt : '2015-01-01T00:00:00.000Z' ,
237+ label : 'foobar' ,
238+ } ,
239+ } )
240+ ) ;
241+
242+ const ajax = jest . fn ( ) ;
243+ CoreManager . setRESTController ( { request : request , ajax : ajax } ) ;
244+
245+ const response1 = await Cloud . run ( 'myfunction' ) ;
246+ expect ( response1 . get ( 'label' ) ) . toBe ( 'foobar' ) ;
247+
248+ request . mockReturnValue (
249+ Promise . resolve ( {
250+ success : true ,
251+ result : {
252+ objectId : 'abc123' ,
253+ className : 'Item' ,
254+ __type : 'Object' ,
255+ createdAt : '2015-01-01T00:00:00.000Z' ,
256+ updatedAt : '2015-01-01T00:00:00.000Z' ,
257+ label2 : 'control to confirm correct mock usage' ,
258+ // Note that 'label' is not returned
259+ } ,
260+ } )
261+ ) ;
262+
263+ const response2 = await Cloud . run ( 'myfunction' ) ;
264+ expect ( response2 . get ( 'label2' ) ) . toBe ( 'control to confirm correct mock usage' ) ;
265+ expect ( response2 . get ( 'label' ) ) . toBe ( undefined ) ; // Failing test PR #1442
266+ } ) ;
267+
219268 it ( 'startJob passes encoded requests' , ( ) => {
220269 Cloud . startJob ( 'myJob' , {
221270 value : 12 ,
0 commit comments