Skip to content
Browse files

Made the example much nicer thanks to Joe Fiorni

  • Loading branch information...
1 parent 5d82546 commit b19e78efc3f9557cf6ee5e9a1ff93d38ca1e6fa4 @searls committed
Showing with 10 additions and 4 deletions.
  1. +10 −4 README.md
View
14 README.md
@@ -17,17 +17,23 @@ One annoyance with Jasmine spies is the default semantics of `Spy#andReturn` lim
Enter jasmine-stealth, which adds a `#when` method to Jasmine's spies. It lets you specify a conditional stubbing by chaining `thenReturn`. Example:
describe("multiple stubbings", function() {
+ var someSpy;
beforeEach(function() {
- spy.when("pirate", { booty: ["jewels",jasmine.any(String)]}).thenReturn("argh!");
- spy.when("panda",1).thenReturn("sad");
+ someSpy = jasmine.createSpy();
+ someSpy.when("pirate", { booty: ["jewels",jasmine.any(String)]}).thenReturn("argh!");
+ someSpy.when("panda",1).thenReturn("sad");
});
it("stubs the first accurately", function() {
- expect(spy("pirate",{ booty: ["jewels","coins"]})).toBe("argh!");
+ expect(someSpy("pirate",{ booty: ["jewels","coins"]})).toBe("argh!");
});
it("stubs the second too", function() {
- expect(spy("panda",1)).toBe("sad");
+ expect(someSpy("panda",1)).toBe("sad");
+ });
+
+ it("doesn't return anything when a stubbing isn't satisfied",function(){
+ expect(someSpy("anything else at all")).not.toBeDefined();
});
});

0 comments on commit b19e78e

Please sign in to comment.
Something went wrong with that request. Please try again.