Skip to content

Commit

Permalink
fix: remove unreachable wrapWord assertion (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
  • Loading branch information
nam-hle and nhle-mgmtp authored Apr 23, 2021
1 parent 48c5bf7 commit 2728d70
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/calculateRowHeightIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export default (rows: Row[], config: BaseConfig): number[] => {
throw new TypeError('column[index].width must be a number.');
}

if (config.columns[index1].wrapWord !== true && config.columns[index1].wrapWord !== false) {
throw new TypeError('column[index].wrapWord must be a boolean.');
}

cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
});

Expand Down
17 changes: 0 additions & 17 deletions test/calculateRowHeightIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ describe('calculateRowHeightIndex', () => {
});
});

context('invalid column wrapWord', () => {
it('throws an TypeError', () => {
expect(() => {
return calculateRowHeightIndex([['a']], {
columns: {
0: {
width: 3,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
wrapWord: 'true',
},
},
});
}).to.be.throw(TypeError, 'column[index].wrapWord must be a boolean.');
});
});

context('single column', () => {
context('cell content width is lesser than column width', () => {
it('is equal to 1', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/configSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const configSamples: {invalid: unknown[], valid: TableUserConfig[], } = {
{columns: {0: {alignment: 'middle'}}},
{columns: {1: {width: '5'}}},
{columns: {1: {wrapWord: 1}}},
{columns: {1: {wrapWord: 'true'}}},
{columns: {1: {truncate: '1'}}},
{columns: {1: {paddingLeft: '1'}}},
{columns: {1: {paddingRight: '1'}}},
Expand All @@ -40,6 +41,7 @@ const configSamples: {invalid: unknown[], valid: TableUserConfig[], } = {
{columnDefault: {alignment: 'middle'}},
{columnDefault: {width: '5'}},
{columnDefault: {wrapWord: 1}},
{columnDefault: {wrapWord: 'true'}},
{columnDefault: {truncate: '1'}},
{columnDefault: {paddingLeft: '1'}},
{columnDefault: {paddingRight: '1'}},
Expand Down Expand Up @@ -145,12 +147,14 @@ const configSamples: {invalid: unknown[], valid: TableUserConfig[], } = {
{columns: {1: {alignment: 'left'}}},
{columns: {1: {width: 5}}},
{columns: {1: {wrapWord: true}}},
{columns: {1: {wrapWord: false}}},
{columns: {1: {truncate: 1}}},
{columns: {1: {paddingLeft: 1}}},
{columns: {1: {paddingRight: 1}}},
{columnDefault: {alignment: 'left'}},
{columnDefault: {width: 5}},
{columnDefault: {wrapWord: true}},
{columnDefault: {wrapWord: false}},
{columnDefault: {truncate: 1}},
{columnDefault: {paddingLeft: 1}},
{columnDefault: {paddingRight: 1}},
Expand Down
32 changes: 31 additions & 1 deletion test/streamConfigSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ const streamConfigSamples: {invalid: unknown[], valid: StreamUserConfig[], } = {
columns: {0: {alignment: 'middle'}},
},

{
columnCount: 3,
columnDefault: {width: 20,
wrapWord: 'true'},
},
{
columnCount: 3,
columnDefault: {width: 20},
columns: {0: {wrapWord: 'true'}},
},
{
columnCount: 3,
columnDefault: {width: 20},
columns: {0: {wrapWord: 1}},
},

// eslint-disable-next-line no-warning-comments
// TODO: Fix the schema so that the following configs are truly invalid
// {border: {topBody: '-'}},
Expand Down Expand Up @@ -183,7 +199,21 @@ const streamConfigSamples: {invalid: unknown[], valid: StreamUserConfig[], } = {
},
},
},

{
columnCount: 3,
columnDefault: {width: 20,
wrapWord: true},
},
{
columnCount: 3,
columnDefault: {width: 20},
columns: {0: {wrapWord: true}},
},
{
columnCount: 3,
columnDefault: {width: 20},
columns: {0: {wrapWord: false}},
},
],
};

Expand Down

0 comments on commit 2728d70

Please sign in to comment.