This repository has been archived by the owner on Feb 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:skatejs/bore
- Loading branch information
Showing
6 changed files
with
473 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": [ | ||
|
@@ -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": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />)); | ||
}) | ||
}); | ||
|
||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
Oops, something went wrong.