Skip to content

Commit c714142

Browse files
author
Mathias Lorenzen
committed
updated promise support.
1 parent 0224570 commit c714142

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

dist/spec/index.test.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
declare class Dummy {
2+
}
13
export declare class Example {
24
a: string;
35
c(arg1: string, arg2: string): string;
46
readonly d: number;
57
v: string;
68
received(stuff: number | string): void;
7-
returnPromise(): Promise<number>;
9+
returnPromise(): Promise<Dummy>;
810
foo(): string;
911
}
12+
export {};

dist/spec/index.test.js

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/spec/index.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/Substitute.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/Substitute.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/index.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { Substitute, Arg } from '../src/Index';
44
import { areArgumentsEqual } from '../src/Utilities';
55
import { OmitProxyMethods, ObjectSubstitute } from '../src/Transformations';
66

7+
class Dummy {
8+
9+
}
10+
711
export class Example {
812
a = "1337";
913

@@ -24,7 +28,7 @@ export class Example {
2428
}
2529

2630
returnPromise() {
27-
return Promise.resolve(1337);
31+
return Promise.resolve(new Dummy());
2832
}
2933

3034
foo() {
@@ -44,6 +48,13 @@ test.beforeEach(() => {
4448
substitute = Substitute.for<Example>();
4549
});
4650

51+
test('returning other fake from promise works', async t => {
52+
const otherSubstitute = Substitute.for<Dummy>();
53+
substitute.returnPromise().returns(Promise.resolve(otherSubstitute));
54+
55+
t.is(otherSubstitute, await substitute.returnPromise());
56+
});
57+
4758
test('returning resolved promises works', async t => {
4859
substitute.returnPromise().returns(Promise.resolve(1338));
4960

src/Substitute.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ export class Substitute {
174174
if (property === 'constructor')
175175
return () => thisProxy;
176176

177+
if(property === 'then')
178+
return void 0;
179+
177180
const currentPropertyContext = objectContext.property;
178181
const addPropertyToObjectContext = () => {
179182
const expected = objectContext.calls.expected;

0 commit comments

Comments
 (0)