Skip to content

Commit

Permalink
Don't mutate argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dino-absoluto committed May 1, 2019
1 parent 728fc34 commit a286e0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/elements/__tests__/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const immediate = (): Promise<void> => {
}

describe('AbstractElement', (): void => {
test('simple', async (): Promise<void> => {
test('simple', async () => {
interface TestI {
a: number
b: number
Expand Down Expand Up @@ -92,14 +92,16 @@ describe('AbstractElement', (): void => {

describe('Base', (): void => {
class TestBase extends Base {
public testWidth = 1
public data = [ 'abc', '#' ]
public handleCalculateWidth (): number {
return 1
return this.testWidth
}
public handleRender (): string[] {
return ['abc', '#']
return this.data
}
}
test('simple', async (): Promise<void> => {
test('simple', async () => {
const b = new TestBase()
expect(b.render()).toBe('abc#')
b.postProcess = (a, b): string => [ b, a ].join('')
Expand All @@ -109,8 +111,15 @@ describe('Base', (): void => {
b.enabled = true
expect(b.render()).toBe('#abc')
expect(b.render(0)).toBe('')
expect(b.calculateWidth()).toBe(1)
})
test('options', async (): Promise<void> => {
test('simple-2', async () => {
const b = new TestBase()
b.data = []
expect(b.render()).toBe('')
expect(b.calculateWidth()).toBe(1)
})
test('options', async () => {
{
const b = new TestBase({
width: 10,
Expand Down Expand Up @@ -144,7 +153,7 @@ describe('Base', (): void => {
expect(b.render()).toBe('#abc')
}
})
test('incorrect value', async (): Promise<void> => {
test('incorrect value', async () => {
const b = new TestBase({
width: 10
})
Expand All @@ -162,7 +171,7 @@ describe('Base', (): void => {
expect(b.flexGrow).toBe(0)
expect(b.flexShrink).toBe(0)
})
test('notify', async (): Promise<void> => {
test('notify', async () => {
const b = new TestBase({
width: 10
})
Expand Down
4 changes: 2 additions & 2 deletions src/elements/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ export abstract class Base
if (postProcess) {
texts = castArray(postProcess(...texts.map((i): string => i.toString())))
}
const first = texts.shift()
const first = texts[0]
if (first != null) {
return first.concat(...texts)
return first.concat(...texts.slice(1))
} else {
return ''
}
Expand Down

0 comments on commit a286e0d

Please sign in to comment.