Comments (6)
"should be possible just like it is in chai" - why not just use chai? Not everything should be extended.
from code.
Why shouldn't everything be able to be extended? That puts power in the hands of the developer and they can continue to use simple, yet powerful libraries. Being able to plug many simple libraries together to make exactly what one needs is far superior than having to use a few things from large libraries.
I'm using code because of it's simplicity but the fact that it can't be extended (which is as simple as exposing a single function) is something I feel is missing from this simple library.
from code.
Because once you allow extensions you need to maintain that API and in many cases, that will limit your ability to make internal changes. It's a long-term PITA. I belong to the No First school of open source leadership.
from code.
I'm going to close this for now, in the same spirit as #39. If anyone can convince @hueniverse that this is a good idea, then we can revisit :-)
from code.
(This comment is intended to detail a full work-around example and the issues with it, and is not intended to be a call to action.)
I would also enjoy the ability to extend Hapi Code to support a custom matcher. Unfortunately, in a typescript project I'm not sure how the @types/code definitions could be made to allow for a seamless use scenario.
Based on the example that @coder13 offered in their OP, I coded up what this might look like using Hapi Lab 18.0.1 / Hapi Code 5.2.4:
Object.getPrototypeOf(expect(null)).uuid = function () {
const isUuid = (input: string) => {
const regex = new RegExp('^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$', 'i');
return regex.test(input);
};
// tslint:disable-next-line: no-invalid-this
return Object.getPrototypeOf(this).assert.call(this, isUuid(this._ref));
};
export interface ExtendedValues<T> extends AssertionChain<T> {
uuid(): AssertionChain<T>;
}
// later, in a test: this generates a warning: Property 'uuid' does not exist on type 'AssertionChain<any>'.
expect('my guid').to.be.a.uuid();
// fixing with a typecast
(expect('my guid').to.be.a as ExtendedValues<string>).uuid();
// or, if you're okay with casting as 'any':
(expect('my guid').to.be.a any).uuid();
// or you could just tell Typescript to shut up about it:
// @ts-ignore: uuid() extension
expect('my guid').to.be.a.uuid();
Note: Replaced the use of deprecated __proto__
with Object.getPrototypeOf
.
The real ugliness is that the grammar is typed, and knows what methods can follow, which would exclude anything layered into the internals.Assertion
prototype because all of the types are implemented separately in @types/code
.
from code.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
from code.
Related Issues (20)
- Typescript types would be super dope HOT 1
- Use deepFunction flag for deep comparison HOT 1
- Support deep comparison key skipping HOT 1
- Deep comparison includes symbols HOT 1
- expect(<'', [], or {}>).to.only.include('foo') passes HOT 2
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- to.only.include(values) passes with values not in reference HOT 2
- Drop node 8
- Add types
- Assertion with 'equal()' fails HOT 1
- Support only node 12
- Update hoek
- Fix function string in node 13
- The type `.rejects` returns should return a Promise HOT 1
- Type error on .include() HOT 7
- Allow simpler tests for error.code HOT 2
- compilation errors for primitive type assertions HOT 2
- equal(value: T) type should be Loosely<T> when options ignore symbols or properties
- pass parameter to throw
- Incorrect prototype check HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from code.