blob: cbfe3e0014428a832a9296b59faa7db52c83d82a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
describe ("Fake", function() {
beforeEach (function() {
sut = new Fake();
});
var sut;
describe ("when stubbing out return values", function() {
describe ("when there are no parameters", function() {
it ("should return the correct value", function() {
expect(result).toEqual("hello");
});
beforeEach (function() {
sut.stub('greet').andReturn('hello');
result = sut.greet();
});
var result;
});
describe ("when there are arguments to match", function() {
describe ("when there is a single input argument", function() {
describe ("when invoked as expected", function() {
it ("should return the value the corresponds to the input arguments", function() {
expect(sut.greet('mo')).toEqual('hello mo');
});
it ("should return the correct value that corresponds to other args", function() {
expect(sut.greet('jo')).toEqual('hello jo');
});
beforeEach (function() {
sut.stub('greet').with('mo').andReturn('hello mo');
sut.stub('greet').with('jo').andReturn('hello jo');
});
});
describe ("when invoked unexpectedly", function() {
it ("should throw an error", function() {
sut.stub('greet').with('mo').andReturn('hello mo');
expect(function(){sut.greet('malcolm');}).toThrow("Matcher not found.");
});
});
});
});
});
});
|