Skip to content

Commit f984f1b

Browse files
test: add overlapping interface regression
1 parent 531a26a commit f984f1b

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

spec/regression/overlap.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import test from 'ava'
2+
3+
import { Substitute, received, didNotReceive } from '../../src'
4+
5+
export interface OverlappingInterface {
6+
received(value: number): string
7+
didNotReceive(): unknown
8+
clearReceivedCalls(): void
9+
}
10+
11+
test('(clearReceivedCalls) handles overlaps safely without substitutions', t => {
12+
const substitute = Substitute.for<Omit<OverlappingInterface, 'received'>>()
13+
substitute.clearReceivedCalls()
14+
t.notThrows(() => substitute.received(1).clearReceivedCalls())
15+
t.throws(() => substitute[didNotReceive]().clearReceivedCalls())
16+
})
17+
18+
test('(clearReceivedCalls) handles overlaps safely with substitutions', t => {
19+
const substitute = Substitute.for<Omit<OverlappingInterface, 'received'>>()
20+
substitute.clearReceivedCalls().returns()
21+
substitute.clearReceivedCalls()
22+
t.notThrows(() => substitute.received(1).clearReceivedCalls())
23+
t.throws(() => substitute[didNotReceive]().clearReceivedCalls())
24+
})
25+
26+
test('(received) handles overlaps safely without substitutions', t => {
27+
const substitute = Substitute.for<Omit<OverlappingInterface, 'didNotReceive'>>()
28+
substitute.received(10)
29+
t.notThrows(() => substitute[received](1).received(10))
30+
t.throws(() => substitute.didNotReceive().received(10))
31+
})
32+
33+
test('(received) handles overlaps safely with substitutions', t => {
34+
const substitute = Substitute.for<Omit<OverlappingInterface, 'didNotReceive'>>()
35+
substitute.received(10).returns('foo')
36+
t.is('foo', substitute.received(10))
37+
t.notThrows(() => substitute[received](1).received(10))
38+
t.throws(() => substitute.didNotReceive().received(10))
39+
})
40+
41+
test('(didNotReceive) handles overlaps safely without substitutions', t => {
42+
const substitute = Substitute.for<Omit<OverlappingInterface, 'received'>>()
43+
substitute.didNotReceive()
44+
t.notThrows(() => substitute.received(1).didNotReceive())
45+
t.throws(() => substitute[didNotReceive]().didNotReceive())
46+
})
47+
48+
test('(didNotReceive) handles overlaps safely with substitutions', t => {
49+
const substitute = Substitute.for<Omit<OverlappingInterface, 'received'>>()
50+
substitute.didNotReceive().returns('foo')
51+
t.is('foo' as unknown, substitute.didNotReceive())
52+
t.notThrows(() => substitute.received(1).didNotReceive())
53+
t.throws(() => substitute[didNotReceive]().didNotReceive())
54+
})

spec/regression/returns.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava'
22
import { types } from 'util'
33

4-
import { Substitute, Arg, returns } from '../../src'
4+
import { Substitute, Arg } from '../../src'
55

66
interface Calculator {
77
add(a: number, b: number): number

0 commit comments

Comments
 (0)