Skip to content

Commit

Permalink
refactor(songParser): Mock short-uuid generate method.
Browse files Browse the repository at this point in the history
This commit refactors the `songParser.spec.ts` file by mocking the `generate` method of the `short-uuid` library. This change allows us to have a consistent ID (`ANY_id`) for testing purposes.
  • Loading branch information
ioanlucut committed Nov 13, 2023
1 parent 1ab9d0c commit ca407c6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/songParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
import { ALLOWED_CHARS, EMPTY_STRING } from './constants.js';
import { createAdvancedSongMock } from './core.js';

jest.mock('short-uuid', () => ({
generate: () => 'ANY_id',
}));

describe('Song parser', () => {
describe('Well structured', () => {
it('should parse a song (w/o subsections) correctly', () => {
Expand Down Expand Up @@ -120,17 +124,16 @@ describe('Song parser', () => {
});

it('should parse a song (w/o correct ID) correctly', () => {
expect(
parse(SIMPLE_SONG_WO_ID__MOCK_FILE_CONTENT)
).toMatchInlineSnapshot(`
expect(parse(SIMPLE_SONG_WO_ID__MOCK_FILE_CONTENT)).
toMatchInlineSnapshot(`
{
"alternative": "alternative 1; alternative 2",
"arranger": "arranger 1; arranger 2",
"band": "band 1; band 2",
"composer": "composer 1; composer 2",
"contentHash": "0173a1",
"genre": "genre 1; genre 2",
"id": "iKi6xsDjgpFEVwrfdumTA4",
"id": "ANY_id",
"interpreter": "interpreter 1; interpreter 2",
"key": "*",
"rcId": "*",
Expand Down

0 comments on commit ca407c6

Please sign in to comment.