Skip to content

Commit

Permalink
improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 10, 2019
1 parent f79ee15 commit d2fdd84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connection-string",
"version": "2.7.0",
"version": "2.7.1",
"description": "Advanced URL Connection String parser + generator.",
"main": "src/index.js",
"typings": "src/index.d.ts",
Expand Down
15 changes: 9 additions & 6 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ function parse(cs, defaults) {
return new ConnectionString(cs, defaults);
}

function parseHost(host) {
return ConnectionString.parseHost(host);
}

function create(obj) {
return (new ConnectionString('', obj)).toString();
}
Expand Down Expand Up @@ -446,8 +450,8 @@ describe('toString', () => {

describe('host.toString()', () => {
it('must generate full host name', () => {
expect(ConnectionString.parseHost('localhost:123').toString()).toBe('localhost:123');
expect(ConnectionString.parseHost('[::]:123').toString()).toBe('[::]:123');
expect(parseHost('localhost:123').toString()).toBe('localhost:123');
expect(parseHost('[::]:123').toString()).toBe('[::]:123');

expect(parse('').setDefaults({
hosts: [{
Expand All @@ -457,8 +461,8 @@ describe('host.toString()', () => {
}).hosts[0].toString()).toBe('localhost:123');
});
it('must encode dollar symbol only when required', () => {
expect(ConnectionString.parseHost('my$server:123').toString()).toBe('my$server:123');
expect(ConnectionString.parseHost('my$server:123').toString({encodeDollar: true})).toBe('my%24server:123');
expect(parseHost('my$server:123').toString()).toBe('my$server:123');
expect(parseHost('my$server:123').toString({encodeDollar: true})).toBe('my%24server:123');

expect(parse('').setDefaults({
hosts: [{
Expand Down Expand Up @@ -585,7 +589,6 @@ describe('setDefaults', () => {
});

describe('parseHost', () => {
const parseHost = ConnectionString.parseHost;
it('must throw on invalid host', () => {
const error = 'Invalid "host" parameter: ';
expect(() => {
Expand All @@ -596,7 +599,7 @@ describe('parseHost', () => {
}).toThrow(error + 123);
});
it('must not decode hosts', () => {
// TODO: must not use partial host names here:
// TODO: should either skip or throw when the host match is partial:
// expect(parseHost('a b')).toEqual(null);
});
it('must allow empty hosts', () => {
Expand Down

0 comments on commit d2fdd84

Please sign in to comment.