You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
4 years ago
|
describe("Player", () => {
|
||
|
var Player = require('../../lib/jasmine_examples/Player');
|
||
|
var Song = require('../../lib/jasmine_examples/Song');
|
||
|
var player;
|
||
|
var song;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
player = new Player();
|
||
|
song = new Song();
|
||
|
});
|
||
|
|
||
|
it("should be able to play a Song", () => {
|
||
|
player.play(song);
|
||
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||
|
|
||
|
//demonstrates use of custom matcher
|
||
|
expect(player).toBePlaying(song);
|
||
|
});
|
||
|
|
||
|
describe("when song has been paused", () => {
|
||
|
beforeEach(() => {
|
||
|
player.play(song);
|
||
|
player.pause();
|
||
|
});
|
||
|
|
||
|
it("should indicate that the song is currently paused", () => {
|
||
|
expect(player.isPlaying).toBeFalsy();
|
||
|
|
||
|
// demonstrates use of 'not' with a custom matcher
|
||
|
expect(player).not.toBePlaying(song);
|
||
|
});
|
||
|
|
||
|
it("should be possible to resume", () => {
|
||
|
player.resume();
|
||
|
expect(player.isPlaying).toBeTruthy();
|
||
|
expect(player.currentlyPlayingSong).toEqual(song);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// demonstrates use of spies to intercept and test method calls
|
||
|
it("tells the current song if the user has made it a favorite", () => {
|
||
|
spyOn(song, 'persistFavoriteStatus');
|
||
|
|
||
|
player.play(song);
|
||
|
player.makeFavorite();
|
||
|
|
||
|
expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
|
||
|
});
|
||
|
|
||
|
//demonstrates use of expected exceptions
|
||
|
describe("#resume", () => {
|
||
|
it("should throw an exception if song is already playing", () => {
|
||
|
player.play(song);
|
||
|
|
||
|
expect(() => {
|
||
|
player.resume();
|
||
|
}).toThrowError("song is already playing");
|
||
|
});
|
||
|
});
|
||
|
});
|