|
| 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 | +}) |
0 commit comments