|
| 1 | +import Call from '../../../src/value/call' |
| 2 | +import Double from '../../../src/value/double' |
| 3 | +import Stubbing from '../../../src/value/stubbing' |
| 4 | +import StubbingRegister from '../../../src/value/stubbing-register' |
| 5 | + |
| 6 | +import subject from '../../../src/satisfy/find-last-stubbing-match' |
| 7 | + |
| 8 | +let stubbingRegister |
| 9 | +module.exports = { |
| 10 | + beforeEach: () => { |
| 11 | + stubbingRegister = StubbingRegister.instance |
| 12 | + }, |
| 13 | + 'no stubbings': () => { |
| 14 | + const double = Double.create() |
| 15 | + const call = new Call(this, []) |
| 16 | + |
| 17 | + const result = subject(double, call) |
| 18 | + |
| 19 | + assert.equal(result, null) |
| 20 | + }, |
| 21 | + '2 stub 1 match': () => { |
| 22 | + const double = Double.create() |
| 23 | + const call = new Call(this, [42]) |
| 24 | + const stubbing1 = new Stubbing('thenBlah', [42], ['blah']) |
| 25 | + const stubbing2 = new Stubbing('thenBlah', [43], ['blah']) |
| 26 | + stubbingRegister.add(double, stubbing1) |
| 27 | + stubbingRegister.add(double, stubbing2) |
| 28 | + |
| 29 | + const result = subject(double, call) |
| 30 | + |
| 31 | + assert.equal(result, stubbing1) |
| 32 | + }, |
| 33 | + '3 stub 2 matches': () => { |
| 34 | + const double = Double.create() |
| 35 | + const call = new Call(this, [42]) |
| 36 | + const stubbing1 = new Stubbing('thenBlah', [42], ['blah']) |
| 37 | + const stubbing2 = new Stubbing('thenBlah', ['pants'], ['blah']) |
| 38 | + const stubbing3 = new Stubbing('thenBlah', [42], ['blah']) |
| 39 | + stubbingRegister.add(double, stubbing1) |
| 40 | + stubbingRegister.add(double, stubbing2) |
| 41 | + stubbingRegister.add(double, stubbing3) |
| 42 | + |
| 43 | + const result = subject(double, call) |
| 44 | + |
| 45 | + assert.equal(result, stubbing3) |
| 46 | + }, |
| 47 | + 'stubbing has limited satisfactions': () => { |
| 48 | + const double = Double.create() |
| 49 | + const call = new Call(this, [42]) |
| 50 | + const stubbing1 = new Stubbing('thenBlah', [42], ['blah']) |
| 51 | + const stubbing2 = new Stubbing('thenBlah', ['pants'], ['blah']) |
| 52 | + const stubbing3 = new Stubbing('thenBlah', [42], ['blah'], {times: 2}) |
| 53 | + stubbingRegister.add(double, stubbing1) |
| 54 | + stubbingRegister.add(double, stubbing2) |
| 55 | + stubbingRegister.add(double, stubbing3) |
| 56 | + stubbing3.incrementSatisfactions() |
| 57 | + stubbing3.incrementSatisfactions() |
| 58 | + |
| 59 | + const result = subject(double, call) |
| 60 | + |
| 61 | + assert.equal(result, stubbing1) |
| 62 | + } |
| 63 | +} |
| 64 | + |
0 commit comments