Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/verse-ref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,27 @@ describe('VerseRef', () => {
describe('Serialization', () => {
it('should serialize empty VerseRef', () => {
const vref = new VerseRef();
expect(vref.toJSON()).toEqual({ book: '', chapterNum: 0, verseNum: 0 });

const json = vref.toJSON();

expect(json).toEqual({ book: '', chapterNum: 0, verseNum: 0 });
// Needed to help .NET deserialization.
expect(json).not.toHaveProperty('verse');
});

it('should serialize VerseRef', () => {
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
expect(vref.toJSON()).toEqual({

const json = vref.toJSON();

expect(json).toEqual({
book: 'GEN',
chapterNum: 2,
verseNum: 3,
versificationStr: 'Septuagint',
});
// Needed to help .NET deserialization.
expect(json).not.toHaveProperty('verse');
});

it('should stringify VerseRef', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/verse-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,15 @@ export class VerseRef {
toJSON(): SerializedVerseRef {
let verse: string | undefined = this.verse;
if (verse === '' || verse === this.verseNum.toString()) verse = undefined;
return {
const json = {
book: this.book,
chapterNum: this.chapterNum,
verseNum: this.verseNum,
verse,
versificationStr: this.versificationStr,
};
if (!verse) delete json.verse;
return json;
}

/**
Expand Down