Skip to content

Commit

Permalink
implementing #24
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 14, 2019
1 parent 4d2166e commit 90373f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class ConnectionString {

constructor(cs: string, defaults?: IConnectionDefaults) {

if (!(this instanceof ConnectionString)) {
throw new TypeError('Class constructor ConnectionString cannot be invoked without \'new\'');
}

if (typeof cs !== 'string') {
throw new TypeError('Invalid connection string: ' + JSON.stringify(cs));
}
Expand Down
5 changes: 5 additions & 0 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ function create(defaults: IConnectionDefaults): string {
}

describe('init', () => {
it('must throw when used as a function', () => {
expect(() => {
(ConnectionString as any)();
}).to.throw('Class constructor ConnectionString cannot be invoked without \'new\'');
});
it('must throw on a non-string', () => {
const error = 'Invalid connection string: ';
expect(() => {
Expand Down

0 comments on commit 90373f1

Please sign in to comment.