Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:skatejs/bore
Browse files Browse the repository at this point in the history
  • Loading branch information
treshugart committed Jan 27, 2017
2 parents d2ea601 + 44b90ff commit eb3cb24
Show file tree
Hide file tree
Showing 6 changed files with 473 additions and 299 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ root = true
end_of_line = lf
insert_final_newline = true

[*.{js,py}]
[*.{ts,js,py}]
charset = utf-8

[*.js,*.json]
[*.ts,*.js,*.json]
indent_style = space
indent_size = 2
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Enzyme-like testing for the DOM.",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"types": "src/index.d.ts",
"author": "Trey Shugart <[email protected]>",
"license": "MIT",
"files": [
Expand All @@ -19,10 +20,13 @@
"semantic-release": "^6.3.2",
"skatejs-build": "^12.1.0",
"skatejs-web-components": "^5.0.0",
"tape": "^4.6.2"
"tape": "^4.6.2",
"typescript": "^2.1.5",
"typescript-formatter": "^4.0.1"
},
"scripts": {
"test": "exit 0",
"test": "npm run test:ts",
"test:ts": "tsfmt -r && tsc -p ./",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"dependencies": {
Expand Down
26 changes: 26 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// UMD library
export as namespace bore;

// Public API
export function mount(htmlOrNode: JSX.Element | JSX.Element[] | string): WrappedNode;
export function h(name: string, attrsOrProps?: Object, ...children: any[]): JSX.Element | JSX.Element[];


interface WrappedNode extends Wrapper {
node: BoreNode,
}

interface Wrapper {
all<T extends HTMLElement>(query: Query<T>): WrappedNode[],
one<T extends HTMLElement>(query: Query<T>): WrappedNode,
has<T extends HTMLElement>(query: Query<T>): boolean,

wait(callback?: (wrapper: WrappedNode) => any): Promise<WrappedNode>,
waitFor(callback: (wrapper: WrappedNode) => boolean, options?: { delay?: number }): Promise<WrappedNode>,
}

type Query<T> = string | JSX.Element | T | ((node: BoreNode) => boolean) | Object;

interface BoreNode extends HTMLElement { }


111 changes: 111 additions & 0 deletions test/index-tests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

import { h, mount } from 'bore';

declare var customElements: any;
declare var describe: any;
declare var it: any;
declare global {
namespace JSX {
interface Element extends HTMLElement { }
interface IntrinsicElements {
[elem: string]: any
}
}
}


class MyElement extends HTMLElement { };
class MyComponent extends HTMLElement { };
function doSomething() { }

{
const wrapper = mount(<div><span /></div>);
console.log(wrapper.one('span').node.localName);
// "span"
}
{
console.log((<div />).localName);
// "div"
}
// https://github.com/treshugart/bore#mounthtmlornode
{
mount(<div><span /></div>);
}

// https://github.com/treshugart/bore#wrapper-api
{
const wrapper = mount(<div><span /></div>);

// https://github.com/treshugart/bore#node
{
// div
mount(<div />).node.localName;
}

// https://github.com/treshugart/bore#allquery
{
// https://github.com/treshugart/bore#element-constructors
{
mount(<div><span /></div>).all(HTMLSpanElement);

customElements.define('my-element', MyElement);

mount(<div><my-element /></div>).all(MyElement);
}

// https://github.com/treshugart/bore#custom-filtering-function
{
mount(<div><span /></div>).all(node => node.localName === 'span');
}

// https://github.com/treshugart/bore#diffing-node-trees
{
mount(<div><span /></div>).all(<span />);
mount(<div><span>test</span></div>).all(<span />);
}

// https://github.com/treshugart/bore#using-an-object-as-criteria
{
mount(<div><span id="test" /></div>).all({ id: 'test' });
mount(<div><span id="test" /></div>).all({ id: 'test', somethingElse: true });
}

// https://github.com/treshugart/bore#selector
{
mount(<div><span id="test" /></div>).all('#test');
}

}

// https://github.com/treshugart/bore#onequery
{
mount(<div><span /></div>).one(<span />);
}

// https://github.com/treshugart/bore#hasquery
{
mount(<div><span /></div>).has(<span />);
}

// https://github.com/treshugart/bore#waitthen
{
mount(<MyComponent />).wait().then(doSomething);

mount(<MyComponent />).wait(doSomething);
}

// waitFor(funcReturnBool[, options = { delay: 1 }])
{
mount(<MyElement />).waitFor(wrapper => wrapper.has(<div />));

describe('my custom element', () => {
it('should have an empty div', () => {
return mount(<MyComponent />).waitFor(w => w.has(<div />));
})
});

}
}



26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "es2015",
"target": "es2016",
"lib": [
"dom",
"es2016"
],
"baseUrl": "./",
"paths": {
"bore": ["./"]
},
"noImplicitAny": true,
"sourceMap": false,
"moduleResolution": "node",
"strictNullChecks": true,
"noEmit": true,
"jsx": "react",
"jsxFactory": "h",
"pretty": true
},
"include": [
"src/index.d.ts",
"test/index-tests.tsx"
]
}
Loading

0 comments on commit eb3cb24

Please sign in to comment.