Skip to content

Commit

Permalink
✅ Improve the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
abidjappie committed Mar 4, 2024
1 parent 6d6dc24 commit b88be92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions spec/unit/movie/movie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,6 @@ describe('Unit Tests ->', function () {
expect(layer.stop).toHaveBeenCalledTimes(0)
})

it('should call user provided `onDraw` after drawing', async function () {
// 1a. Force currentTime to 0
mockTime(0)

// 1b. Layer must be inactive to start
const layer = movie.layers[0]
layer.active = false

// 2a. Prepare options object with onDraw callback
const options = jasmine.createSpyObj('options', ['onDraw'])

// 2b. Play one frame at the beginning of the movie with the spy options
await movie.play(options)

// 3. Make sure onDraw was called
expect(options.onDraw).toHaveBeenCalledTimes(1)
})

it('should be able to operate after a layer has been deleted', async function () {
mockTime()

Expand Down Expand Up @@ -293,6 +275,28 @@ describe('Unit Tests ->', function () {
})
})

it('should call user provided `onDraw` after drawing', async function () {
mockTime(0, 500)

// Prepare options object with onDraw callback
let callCount = 0
await movie.play({
onStart: () => {
// The call count should be 0 at the start
expect(callCount).toBe(0)
expect(movie.currentTime).toBe(0)
},
onDraw: () => {
// Set the step to be 500 ms
// So we expect the currentTime to be 0.5 after the first draw
expect(movie.currentTime).toBe(0.5)
callCount++
}
})
// The call count should be 1 at the end
expect(callCount).toBe(1)
})

it('should have an active stream while streaming', async function () {
mockTime()

Expand Down
2 changes: 1 addition & 1 deletion src/movie/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export class Movie {
* Plays the movie
*
* @param [options]
* @param [options.onDraw] Called when the current frame is drawn to the canvas
* @param [options.onStart] Called when the movie starts playing
* @param [options.duration] The duration of the movie to play in seconds
*
* @return Fulfilled when the movie is done playing, never fails
*/
async play (options: {
Expand Down

0 comments on commit b88be92

Please sign in to comment.