@@ -100,7 +100,7 @@ describe("mocking", () => {
100
100
const result = foo . getGenericTypedValue ( ) ;
101
101
102
102
// then
103
- expect ( expectedResult ) . toEqual ( result ) ;
103
+ expect ( result ) . toEqual ( expectedResult ) ;
104
104
} ) ;
105
105
106
106
it ( "does create own property descriptors on instance" , ( ) => {
@@ -223,21 +223,21 @@ describe("mocking", () => {
223
223
} ) ;
224
224
225
225
describe ( "mock an interface with properties" , ( ) => {
226
- let mockedFoo : SamplePropertyInterface ;
227
- let foo : SamplePropertyInterface ;
226
+ let mockedFoo : SampleInterface ;
227
+ let foo : SampleInterface ;
228
228
229
229
if ( typeof Proxy !== "undefined" ) {
230
230
it ( "can setup call actions" , ( ) => {
231
231
// given
232
232
mockedFoo = imock ( MockPropertyPolicy . StubAsProperty ) ;
233
233
foo = instance ( mockedFoo ) ;
234
- when ( mockedFoo . foo ) . thenReturn ( "value" ) ;
234
+ when ( mockedFoo . sampleProperty ) . thenReturn ( "value" ) ;
235
235
236
236
// when
237
- const result = foo . foo ;
237
+ const result = foo . sampleProperty ;
238
238
239
239
// then
240
- verify ( mockedFoo . foo ) . called ( ) ;
240
+ verify ( mockedFoo . sampleProperty ) . called ( ) ;
241
241
expect ( result ) . toBe ( "value" ) ;
242
242
} ) ;
243
243
@@ -247,31 +247,31 @@ describe("mocking", () => {
247
247
foo = instance ( mockedFoo ) ;
248
248
249
249
// when
250
- const result = foo . foo ;
250
+ const result = foo . sampleProperty ;
251
251
252
252
// then
253
- verify ( mockedFoo . foo ) . called ( ) ;
253
+ verify ( mockedFoo . sampleProperty ) . called ( ) ;
254
254
expect ( result ) . toBe ( null ) ;
255
255
} ) ;
256
256
}
257
257
} ) ;
258
258
259
259
describe ( "mock an interface with default policy to throw" , ( ) => {
260
- let mockedFoo : SamplePropertyInterface ;
261
- let foo : SamplePropertyInterface ;
260
+ let mockedFoo : SampleInterface ;
261
+ let foo : SampleInterface ;
262
262
263
263
if ( typeof Proxy !== "undefined" ) {
264
264
it ( "can setup call actions" , ( ) => {
265
265
// given
266
266
mockedFoo = imock ( MockPropertyPolicy . Throw ) ;
267
267
foo = instance ( mockedFoo ) ;
268
- when ( mockedFoo . foo ) . thenReturn ( "value" ) ;
268
+ when ( mockedFoo . sampleProperty ) . thenReturn ( "value" ) ;
269
269
270
270
// when
271
- const result = foo . foo ;
271
+ const result = foo . sampleProperty ;
272
272
273
273
// then
274
- verify ( mockedFoo . foo ) . called ( ) ;
274
+ verify ( mockedFoo . sampleProperty ) . called ( ) ;
275
275
expect ( result ) . toBe ( "value" ) ;
276
276
} ) ;
277
277
@@ -281,12 +281,33 @@ describe("mocking", () => {
281
281
foo = instance ( mockedFoo ) ;
282
282
283
283
// when
284
- expect ( ( ) => foo . foo ) . toThrow ( ) ;
284
+ expect ( ( ) => foo . sampleProperty ) . toThrow ( ) ;
285
285
286
286
// then
287
287
} ) ;
288
288
}
289
289
} ) ;
290
+
291
+ describe ( "mock an interface with both properties and methods" , ( ) => {
292
+ let mockedFoo : SampleInterface ;
293
+ let foo : SampleInterface ;
294
+
295
+ if ( typeof Proxy !== "undefined" ) {
296
+ it ( "can setup call actions on methods" , ( ) => {
297
+ // given
298
+ mockedFoo = imock ( MockPropertyPolicy . StubAsProperty ) ;
299
+ foo = instance ( mockedFoo ) ;
300
+ when ( mockedFoo . sampleMethod ( ) ) . thenReturn ( 5 ) ;
301
+
302
+ // when
303
+ const result = foo . sampleMethod ( ) ;
304
+
305
+ // then
306
+ verify ( mockedFoo . sampleMethod ( ) ) . called ( ) ;
307
+ expect ( result ) . toBe ( 5 ) ;
308
+ } ) ;
309
+ }
310
+ } ) ;
290
311
} ) ;
291
312
292
313
abstract class SampleAbstractClass {
@@ -312,17 +333,16 @@ abstract class SampleAbstractClass {
312
333
interface SampleInterface {
313
334
dependency : Bar ;
314
335
315
- sampleMethod ( ) : number ;
316
- }
336
+ sampleProperty : string ;
317
337
318
- interface SamplePropertyInterface {
319
- foo : string ;
320
- bar : number ;
338
+ sampleMethod ( ) : number ;
321
339
}
322
340
323
341
class SampleInterfaceImplementation implements SampleInterface {
324
342
public dependency : Bar ;
325
343
344
+ public sampleProperty : "999" ;
345
+
326
346
public sampleMethod ( ) : number {
327
347
return 999 ;
328
348
}
0 commit comments