[@commercetools/enzyme-extensions] Add types

This commit is contained in:
Christian Rackerseder 2018-11-02 16:01:31 +01:00
parent f8721b6253
commit 6f37c19a96
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import React = require('react');
import enzyme = require('enzyme');
import configureExtensions = require('@commercetools/enzyme-extensions');
configureExtensions(enzyme.ShallowWrapper);
function App() {
return <Child cb={() => 'Hello world'} />;
}
interface ChildProps {
cb: () => string;
}
function Child(props: ChildProps) {
return <div>{props.cb()}</div>;
}
enzyme.shallow(<App />)
.find(App)
.renderProp('render');
enzyme.shallow(<App />)
.find(Child)
.renderProp('render', 1, 2);
enzyme.shallow(<App />)
.find(Child)
.drill(props => props.cb());
enzyme.shallow(<App />).until(Child);

View File

@ -0,0 +1,22 @@
// Type definitions for @commercetools/enzyme-extensions 3.0
// Project: https://github.com/commercetools/enzyme-extensions
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as enzyme from 'enzyme';
declare module 'enzyme' {
interface UntilOptions {
maxDepth: number;
}
interface ShallowWrapper<P = {}> {
renderProp(propName: string, ...args: any[]): ShallowWrapper<P>;
drill(expander: (props: any) => ShallowWrapper): ShallowWrapper<P>;
until(selector: EnzymeSelector, options?: UntilOptions): ShallowWrapper<P>;
}
}
declare function monkeyPatchShallowWrapper(s: typeof enzyme.ShallowWrapper): void;
export = monkeyPatchShallowWrapper;

View File

@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"paths": {
"@commercetools/enzyme-extensions": ["commercetools__enzyme-extensions"]
}
},
"files": [
"index.d.ts",
"commercetools__enzyme-extensions-tests.tsx"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }