Daniel@0
|
1 describe("Player", function() {
|
Daniel@0
|
2 var player;
|
Daniel@0
|
3 var song;
|
Daniel@0
|
4
|
Daniel@0
|
5 beforeEach(function() {
|
Daniel@0
|
6 player = new Player();
|
Daniel@0
|
7 song = new Song();
|
Daniel@0
|
8 });
|
Daniel@0
|
9
|
Daniel@0
|
10 it("should be able to play a Song", function() {
|
Daniel@0
|
11 player.play(song);
|
Daniel@0
|
12 expect(player.currentlyPlayingSong).toEqual(song);
|
Daniel@0
|
13
|
Daniel@0
|
14 //demonstrates use of custom matcher
|
Daniel@0
|
15 expect(player).toBePlaying(song);
|
Daniel@0
|
16 });
|
Daniel@0
|
17
|
Daniel@0
|
18 describe("when song has been paused", function() {
|
Daniel@0
|
19 beforeEach(function() {
|
Daniel@0
|
20 player.play(song);
|
Daniel@0
|
21 player.pause();
|
Daniel@0
|
22 });
|
Daniel@0
|
23
|
Daniel@0
|
24 it("should indicate that the song is currently paused", function() {
|
Daniel@0
|
25 expect(player.isPlaying).toBeFalsy();
|
Daniel@0
|
26
|
Daniel@0
|
27 // demonstrates use of 'not' with a custom matcher
|
Daniel@0
|
28 expect(player).not.toBePlaying(song);
|
Daniel@0
|
29 });
|
Daniel@0
|
30
|
Daniel@0
|
31 it("should be possible to resume", function() {
|
Daniel@0
|
32 player.resume();
|
Daniel@0
|
33 expect(player.isPlaying).toBeTruthy();
|
Daniel@0
|
34 expect(player.currentlyPlayingSong).toEqual(song);
|
Daniel@0
|
35 });
|
Daniel@0
|
36 });
|
Daniel@0
|
37
|
Daniel@0
|
38 // demonstrates use of spies to intercept and test method calls
|
Daniel@0
|
39 it("tells the current song if the user has made it a favorite", function() {
|
Daniel@0
|
40 spyOn(song, 'persistFavoriteStatus');
|
Daniel@0
|
41
|
Daniel@0
|
42 player.play(song);
|
Daniel@0
|
43 player.makeFavorite();
|
Daniel@0
|
44
|
Daniel@0
|
45 expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
|
Daniel@0
|
46 });
|
Daniel@0
|
47
|
Daniel@0
|
48 //demonstrates use of expected exceptions
|
Daniel@0
|
49 describe("#resume", function() {
|
Daniel@0
|
50 it("should throw an exception if song is already playing", function() {
|
Daniel@0
|
51 player.play(song);
|
Daniel@0
|
52
|
Daniel@0
|
53 expect(function() {
|
Daniel@0
|
54 player.resume();
|
Daniel@0
|
55 }).toThrowError("song is already playing");
|
Daniel@0
|
56 });
|
Daniel@0
|
57 });
|
Daniel@0
|
58 });
|