Skip to content

Commit

Permalink
Added type definitions for Chai UUID (DefinitelyTyped#25227)
Browse files Browse the repository at this point in the history
* Added types for Chai UUID

* Fixed the test file

* Removed the message parameter because it's not implemented in the plugin

* Removed an empty namespace as it was unnecessary
  • Loading branch information
harm-less authored and weswigham committed Apr 25, 2018
1 parent 48e4b60 commit 4ed4461
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
15 changes: 15 additions & 0 deletions types/chai-uuid/chai-uuid-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { assert, expect, use, should } from 'chai';
import chaiUuid = require('chai-uuid');

use(chaiUuid);
should();

// bdd style
expect('67cb8aa1-61bb-4b9b-8ca9-9dc0b278d5f7').to.be.uuid('v4');
expect('67cb8aa1-61bb-4b9b-8ca9-9dc0b278d5f7').to.be.guid;
expect('invalid').to.not.be.uuid('v4');
expect('invalid').to.not.be.guid();

// tdd style
assert.uuid('67cb8aa1-61bb-4b9b-8ca9-9dc0b278d5f7', 'v4');
assert.guid('67cb8aa1-61bb-4b9b-8ca9-9dc0b278d5f7');
27 changes: 27 additions & 0 deletions types/chai-uuid/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Type definitions for chai-uuid 1.0
// Project: https://github.com/rfrench/chai-uuid
// Definitions by: Harm van der Werf <https://github.com/harm-less>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

/// <reference types="node" />
/// <reference types="chai" />

declare global {
namespace Chai {
type UuidVersion = 'v1' | 'v2' | 'v3' | 'v4' | 'v5' | '';

interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
uuid(uuid?: UuidVersion): void;
guid(guid?: any): void;
}

interface Assert {
uuid(uuid: string, version?: UuidVersion): void;
guid(guid: string, version?: any): void;
}
}
}

declare function chaiUuid(chai: any, utils: any): void;
export = chaiUuid;
23 changes: 23 additions & 0 deletions types/chai-uuid/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"chai-uuid-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/chai-uuid/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 4ed4461

Please sign in to comment.