Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): cover async, buffer, map, and reflect utils
- Loading branch information
Showing
4 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { defer, timeout } from '../../src/utils/Async'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
import { TimeoutError } from '../../src'; | ||
|
||
describeLeaks('async utils', async () => { | ||
describeLeaks('defer', async () => { | ||
itLeaks('should resolve', async () => expect(defer(10, true)).to.eventually.equal(true)); | ||
}); | ||
|
||
describeLeaks('timeout', async () => { | ||
itLeaks('should reject slow promises', async () => expect(timeout(10, defer(20))).to.eventually.be.rejectedWith(TimeoutError)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { concat, encode } from '../../src/utils/Buffer'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
|
||
describeLeaks('buffer utils', async () => { | ||
describeLeaks('concat', async () => { | ||
itLeaks('should append chunk buffers', async () => { | ||
expect(concat([ | ||
Buffer.from('hello'), | ||
Buffer.from('world'), | ||
])).to.deep.equal(Buffer.from('helloworld')); | ||
}); | ||
}); | ||
|
||
describeLeaks('encode', async () => { | ||
itLeaks('should encode chunk buffers', async () => { | ||
expect(encode([ | ||
Buffer.from('hello world'), | ||
], 'utf-8')).to.equal('hello world'); | ||
}); | ||
|
||
itLeaks('should encode no buffers', async () => { | ||
expect(encode([], 'utf-8')).to.equal(''); | ||
}); | ||
|
||
itLeaks('should encode empty buffers', async () => { | ||
expect(encode([ | ||
new Buffer(0), | ||
], 'utf-8')).to.equal(''); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from 'chai'; | ||
import { getMethods } from '../../src/utils/Reflect'; | ||
|
||
describe('reflect utils', () => { | ||
describe('get methods helper', () => { | ||
it('should collect method functions', () => { | ||
class Test { | ||
public foo() { /* noop */ } | ||
public bar() { /* noop */ } | ||
} | ||
|
||
const methods = getMethods(new Test()).values(); | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
expect(methods).to.include(Test.prototype.foo); | ||
expect(methods).to.include(Test.prototype.bar); | ||
}); | ||
}); | ||
}); |