From 44f331f43d1b8b5c46578fba3ee22ebbd6c2ced5 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 17 Sep 2022 12:00:20 -0700 Subject: [PATCH] Updated the style of the examples * const/let instead of var * classes * pass our own eslint checks --- .../lib/jasmine_examples/Player.js | 38 +++++++++---------- .../node_example/lib/jasmine_examples/Song.js | 11 +++--- .../helpers/jasmine_examples/SpecHelper.js | 4 +- .../spec/jasmine_examples/PlayerSpec.js | 29 +++++++------- lib/jasmine-core/example/spec/PlayerSpec.js | 24 ++++++------ lib/jasmine-core/example/spec/SpecHelper.js | 2 +- lib/jasmine-core/example/src/Player.js | 38 +++++++++---------- lib/jasmine-core/example/src/Song.js | 11 +++--- 8 files changed, 78 insertions(+), 79 deletions(-) diff --git a/lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js b/lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js index fe95f894..8a7bfbdc 100644 --- a/lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js +++ b/lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js @@ -1,24 +1,24 @@ -function Player() { -} -Player.prototype.play = function(song) { - this.currentlyPlayingSong = song; - this.isPlaying = true; -}; - -Player.prototype.pause = function() { - this.isPlaying = false; -}; - -Player.prototype.resume = function() { - if (this.isPlaying) { - throw new Error("song is already playing"); +class Player { + play(song) { + this.currentlyPlayingSong = song; + this.isPlaying = true; } - this.isPlaying = true; -}; + pause() { + this.isPlaying = false; + } -Player.prototype.makeFavorite = function() { - this.currentlyPlayingSong.persistFavoriteStatus(true); -}; + resume() { + if (this.isPlaying) { + throw new Error('song is already playing'); + } + + this.isPlaying = true; + } + + makeFavorite() { + this.currentlyPlayingSong.persistFavoriteStatus(true); + } +} module.exports = Player; diff --git a/lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js b/lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js index 3415bb82..f2757786 100644 --- a/lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js +++ b/lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js @@ -1,9 +1,8 @@ -function Song() { +class Song { + persistFavoriteStatus(value) { + // something complicated + throw new Error('not yet implemented'); + } } -Song.prototype.persistFavoriteStatus = function(value) { - // something complicated - throw new Error("not yet implemented"); -}; - module.exports = Song; diff --git a/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js b/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js index 578b3e86..cc04bd8d 100644 --- a/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js +++ b/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js @@ -3,11 +3,11 @@ beforeEach(function () { toBePlaying: function () { return { compare: function (actual, expected) { - var player = actual; + const player = actual; return { pass: player.currentlyPlayingSong === expected && player.isPlaying - } + }; } }; } diff --git a/lib/jasmine-core/example/node_example/spec/jasmine_examples/PlayerSpec.js b/lib/jasmine-core/example/node_example/spec/jasmine_examples/PlayerSpec.js index 80f149e3..fa96ccc4 100644 --- a/lib/jasmine-core/example/node_example/spec/jasmine_examples/PlayerSpec.js +++ b/lib/jasmine-core/example/node_example/spec/jasmine_examples/PlayerSpec.js @@ -1,36 +1,37 @@ -describe("Player", function() { - var Player = require('../../lib/jasmine_examples/Player'); - var Song = require('../../lib/jasmine_examples/Song'); - var player; - var song; +const Player = require('../../lib/jasmine_examples/Player'); +const Song = require('../../lib/jasmine_examples/Song'); + +describe('Player', function() { + let player; + let song; beforeEach(function() { player = new Player(); song = new Song(); }); - it("should be able to play a Song", function() { + it('should be able to play a Song', function() { player.play(song); expect(player.currentlyPlayingSong).toEqual(song); - //demonstrates use of custom matcher + // demonstrates use of custom matcher expect(player).toBePlaying(song); }); - describe("when song has been paused", function() { + describe('when song has been paused', function() { beforeEach(function() { player.play(song); player.pause(); }); - it("should indicate that the song is currently paused", function() { + it('should indicate that the song is currently paused', function() { expect(player.isPlaying).toBeFalsy(); // demonstrates use of 'not' with a custom matcher expect(player).not.toBePlaying(song); }); - it("should be possible to resume", function() { + it('should be possible to resume', function() { player.resume(); expect(player.isPlaying).toBeTruthy(); expect(player.currentlyPlayingSong).toEqual(song); @@ -38,7 +39,7 @@ describe("Player", function() { }); // demonstrates use of spies to intercept and test method calls - it("tells the current song if the user has made it a favorite", function() { + it('tells the current song if the user has made it a favorite', function() { spyOn(song, 'persistFavoriteStatus'); player.play(song); @@ -48,13 +49,13 @@ describe("Player", function() { }); //demonstrates use of expected exceptions - describe("#resume", function() { - it("should throw an exception if song is already playing", function() { + describe('#resume', function() { + it('should throw an exception if song is already playing', function() { player.play(song); expect(function() { player.resume(); - }).toThrowError("song is already playing"); + }).toThrowError('song is already playing'); }); }); }); diff --git a/lib/jasmine-core/example/spec/PlayerSpec.js b/lib/jasmine-core/example/spec/PlayerSpec.js index f17521fd..9617c4f4 100644 --- a/lib/jasmine-core/example/spec/PlayerSpec.js +++ b/lib/jasmine-core/example/spec/PlayerSpec.js @@ -1,34 +1,34 @@ -describe("Player", function() { - var player; - var song; +describe('Player', function() { + let player; + let song; beforeEach(function() { player = new Player(); song = new Song(); }); - it("should be able to play a Song", function() { + it('should be able to play a Song', function() { player.play(song); expect(player.currentlyPlayingSong).toEqual(song); - //demonstrates use of custom matcher + // demonstrates use of custom matcher expect(player).toBePlaying(song); }); - describe("when song has been paused", function() { + describe('when song has been paused', function() { beforeEach(function() { player.play(song); player.pause(); }); - it("should indicate that the song is currently paused", function() { + it('should indicate that the song is currently paused', function() { expect(player.isPlaying).toBeFalsy(); // demonstrates use of 'not' with a custom matcher expect(player).not.toBePlaying(song); }); - it("should be possible to resume", function() { + it('should be possible to resume', function() { player.resume(); expect(player.isPlaying).toBeTruthy(); expect(player.currentlyPlayingSong).toEqual(song); @@ -36,7 +36,7 @@ describe("Player", function() { }); // demonstrates use of spies to intercept and test method calls - it("tells the current song if the user has made it a favorite", function() { + it('tells the current song if the user has made it a favorite', function() { spyOn(song, 'persistFavoriteStatus'); player.play(song); @@ -46,13 +46,13 @@ describe("Player", function() { }); //demonstrates use of expected exceptions - describe("#resume", function() { - it("should throw an exception if song is already playing", function() { + describe('#resume', function() { + it('should throw an exception if song is already playing', function() { player.play(song); expect(function() { player.resume(); - }).toThrowError("song is already playing"); + }).toThrowError('song is already playing'); }); }); }); diff --git a/lib/jasmine-core/example/spec/SpecHelper.js b/lib/jasmine-core/example/spec/SpecHelper.js index 126752d1..cc04bd8d 100644 --- a/lib/jasmine-core/example/spec/SpecHelper.js +++ b/lib/jasmine-core/example/spec/SpecHelper.js @@ -3,7 +3,7 @@ beforeEach(function () { toBePlaying: function () { return { compare: function (actual, expected) { - var player = actual; + const player = actual; return { pass: player.currentlyPlayingSong === expected && player.isPlaying diff --git a/lib/jasmine-core/example/src/Player.js b/lib/jasmine-core/example/src/Player.js index 11851966..f2fae6f7 100644 --- a/lib/jasmine-core/example/src/Player.js +++ b/lib/jasmine-core/example/src/Player.js @@ -1,22 +1,22 @@ -function Player() { -} -Player.prototype.play = function(song) { - this.currentlyPlayingSong = song; - this.isPlaying = true; -}; - -Player.prototype.pause = function() { - this.isPlaying = false; -}; - -Player.prototype.resume = function() { - if (this.isPlaying) { - throw new Error("song is already playing"); +class Player { + play(song) { + this.currentlyPlayingSong = song; + this.isPlaying = true; } - this.isPlaying = true; -}; + pause() { + this.isPlaying = false; + } -Player.prototype.makeFavorite = function() { - this.currentlyPlayingSong.persistFavoriteStatus(true); -}; + resume() { + if (this.isPlaying) { + throw new Error('song is already playing'); + } + + this.isPlaying = true; + } + + makeFavorite() { + this.currentlyPlayingSong.persistFavoriteStatus(true); + } +} diff --git a/lib/jasmine-core/example/src/Song.js b/lib/jasmine-core/example/src/Song.js index 02527cb1..8914793b 100644 --- a/lib/jasmine-core/example/src/Song.js +++ b/lib/jasmine-core/example/src/Song.js @@ -1,7 +1,6 @@ -function Song() { +class Song { + persistFavoriteStatus(value) { + // something complicated + throw new Error('not yet implemented'); + } } - -Song.prototype.persistFavoriteStatus = function(value) { - // something complicated - throw new Error("not yet implemented"); -};