test-drive-react
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,3 +5,2 @@ import React from 'react'; | ||
container: HTMLDivElement; | ||
result: void | Element | React.Component<P>; | ||
select(...selectors: string[]): Element | null; | ||
@@ -8,0 +7,0 @@ ensuredSelect(...selectors: string[]): Element; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ClientRenderer = void 0; | ||
const react_dom_1 = __importDefault(require("react-dom")); | ||
@@ -20,7 +21,6 @@ const test_drive_1 = require("test-drive"); | ||
} | ||
const result = react_dom_1.default.render(element, container); | ||
react_dom_1.default.render(element, container); | ||
const select = test_drive_1.selectDom(container); | ||
return { | ||
container, | ||
result, | ||
select, | ||
@@ -41,5 +41,5 @@ ensuredSelect(...selectors) { | ||
driver, | ||
container: container | ||
container: container, | ||
}; | ||
} | ||
}, | ||
}; | ||
@@ -46,0 +46,0 @@ } |
@@ -10,3 +10,3 @@ import React from 'react'; | ||
get root(): E; | ||
get ensuredRoot(): E; | ||
get ensuredRoot(): NonNullable<E>; | ||
protected select(...selectors: string[]): Element | null; | ||
@@ -13,0 +13,0 @@ protected ensuredSelect(...selectors: string[]): Element; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DriverBase = void 0; | ||
const test_drive_1 = require("test-drive"); | ||
@@ -19,7 +20,7 @@ class DriverBase { | ||
select(...selectors) { | ||
const { ensuredRoot } = this; | ||
if (!(ensuredRoot instanceof Element)) { | ||
throw new Error(`root is not an Element.`); | ||
const { root } = this; | ||
if (!(root instanceof Element)) { | ||
return null; | ||
} | ||
return test_drive_1.selectDom(ensuredRoot)(...selectors); | ||
return test_drive_1.selectDom(root)(...selectors); | ||
} | ||
@@ -26,0 +27,0 @@ ensuredSelect(...selectors) { |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var test_utils_1 = require("react-dom/test-utils"); | ||
exports.Simulate = test_utils_1.Simulate; | ||
__export(require("test-drive")); | ||
__export(require("./client-renderer")); | ||
__export(require("./driver-base")); | ||
Object.defineProperty(exports, "Simulate", { enumerable: true, get: function () { return test_utils_1.Simulate; } }); | ||
__exportStar(require("test-drive"), exports); | ||
__exportStar(require("./client-renderer"), exports); | ||
__exportStar(require("./driver-base"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,2 @@ import React from 'react'; | ||
container: HTMLDivElement; | ||
result: void | Element | React.Component<P>; | ||
select(...selectors: string[]): Element | null; | ||
@@ -8,0 +7,0 @@ ensuredSelect(...selectors: string[]): Element; |
@@ -14,7 +14,6 @@ import ReactDOM from 'react-dom'; | ||
} | ||
const result = ReactDOM.render(element, container); | ||
ReactDOM.render(element, container); | ||
const select = selectDom(container); | ||
return { | ||
container, | ||
result, | ||
select, | ||
@@ -35,5 +34,5 @@ ensuredSelect(...selectors) { | ||
driver, | ||
container: container | ||
container: container, | ||
}; | ||
} | ||
}, | ||
}; | ||
@@ -40,0 +39,0 @@ } |
@@ -10,3 +10,3 @@ import React from 'react'; | ||
get root(): E; | ||
get ensuredRoot(): E; | ||
get ensuredRoot(): NonNullable<E>; | ||
protected select(...selectors: string[]): Element | null; | ||
@@ -13,0 +13,0 @@ protected ensuredSelect(...selectors: string[]): Element; |
@@ -17,7 +17,7 @@ import { selectDom } from 'test-drive'; | ||
select(...selectors) { | ||
const { ensuredRoot } = this; | ||
if (!(ensuredRoot instanceof Element)) { | ||
throw new Error(`root is not an Element.`); | ||
const { root } = this; | ||
if (!(root instanceof Element)) { | ||
return null; | ||
} | ||
return selectDom(ensuredRoot)(...selectors); | ||
return selectDom(root)(...selectors); | ||
} | ||
@@ -24,0 +24,0 @@ ensuredSelect(...selectors) { |
{ | ||
"name": "test-drive-react", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Opinionated library for Test-Driven Development of React Components.", | ||
@@ -10,11 +10,11 @@ "main": "./cjs/index.js", | ||
"clean": "rimraf ./cjs ./esm", | ||
"prebuild": "yarn clean", | ||
"build": "yarn build:cjs && yarn build:esm", | ||
"prebuild": "npm run clean", | ||
"build": "npm run build:cjs && npm run build:esm", | ||
"build:cjs": "tsc -p tsconfig.build.json --outDir cjs --module commonjs", | ||
"build:esm": "tsc -p tsconfig.build.json --outDir esm --module esnext", | ||
"typecheck": "tsc --noEmit", | ||
"lint": "eslint . --ext .ts,.tsx -f codeframe", | ||
"pretest": "yarn typecheck && yarn lint", | ||
"lint": "eslint . -f codeframe", | ||
"pretest": "npm run typecheck && npm run lint", | ||
"test": "mocha-pup \"./test/**/*.ts?(x)\"", | ||
"prepack": "yarn build" | ||
"prepack": "npm run build" | ||
}, | ||
@@ -26,26 +26,26 @@ "peerDependencies": { | ||
"dependencies": { | ||
"test-drive": "^1.1.0" | ||
"test-drive": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"@ts-tools/webpack-loader": "^1.1.2", | ||
"@types/chai": "^4.2.7", | ||
"@types/chai-dom": "^0.0.8", | ||
"@types/mocha": "^5.2.7", | ||
"@types/react": "^16.9.17", | ||
"@types/react-dom": "^16.9.4", | ||
"@types/sinon": "^7.5.1", | ||
"@types/sinon-chai": "^3.2.3", | ||
"@typescript-eslint/eslint-plugin": "^2.15.0", | ||
"@typescript-eslint/parser": "^2.15.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-plugin-react": "^7.17.0", | ||
"mocha": "^7.0.0", | ||
"mocha-pup": "^2.0.0", | ||
"puppeteer": "^2.0.0", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"rimraf": "^3.0.0", | ||
"typescript": "~3.7.4", | ||
"webpack": "^4.41.5" | ||
"@ts-tools/webpack-loader": "^1.1.4", | ||
"@types/chai": "^4.2.11", | ||
"@types/chai-dom": "^0.0.10", | ||
"@types/mocha": "^7.0.2", | ||
"@types/react": "^16.9.38", | ||
"@types/react-dom": "^16.9.8", | ||
"@types/sinon": "^9.0.4", | ||
"@types/sinon-chai": "^3.2.4", | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"eslint": "^7.3.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-react": "^7.20.0", | ||
"mocha": "^8.0.1", | ||
"mocha-pup": "^3.0.2", | ||
"puppeteer": "^4.0.0", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"rimraf": "^3.0.2", | ||
"typescript": "~3.9.5", | ||
"webpack": "^4.43.0" | ||
}, | ||
@@ -66,3 +66,8 @@ "files": [ | ||
"homepage": "https://github.com/wixplosives/test-drive-react#readme", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"prettier": { | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
} | ||
} |
# test-drive-react | ||
[![npm version](https://badge.fury.io/js/test-drive-react.svg)](https://www.npmjs.com/package/test-drive-react) | ||
[![Build Status](https://github.com/wixplosives/test-drive-react/workflows/CI/badge.svg)](https://github.com/wixplosives/test-drive-react/actions) | ||
[![Build Status](https://github.com/wixplosives/test-drive-react/workflows/tests/badge.svg)](https://github.com/wixplosives/test-drive-react/actions) | ||
@@ -5,0 +5,0 @@ Opinionated library for Test-Driven Development of React components, extending |
@@ -8,3 +8,2 @@ import React from 'react'; | ||
container: HTMLDivElement; | ||
result: void | Element | React.Component<P>; | ||
select(...selectors: string[]): Element | null; | ||
@@ -33,7 +32,6 @@ ensuredSelect(...selectors: string[]): Element; | ||
} | ||
const result = ReactDOM.render(element, container); | ||
ReactDOM.render(element, container); | ||
const select = selectDom(container); | ||
return { | ||
container, | ||
result, | ||
select, | ||
@@ -56,9 +54,9 @@ ensuredSelect(...selectors) { | ||
driver, | ||
container: container! | ||
container: container!, | ||
}; | ||
} | ||
}, | ||
}; | ||
} | ||
public cleanup() { | ||
public cleanup(): void { | ||
for (const container of this.containers) { | ||
@@ -65,0 +63,0 @@ ReactDOM.unmountComponentAtNode(container); |
@@ -12,7 +12,7 @@ import React from 'react'; | ||
public get root() { | ||
public get root(): E { | ||
return this.rootNodeEval(); | ||
} | ||
public get ensuredRoot() { | ||
public get ensuredRoot(): NonNullable<E> { | ||
const root = this.rootNodeEval(); | ||
@@ -22,14 +22,14 @@ if (root === null) { | ||
} | ||
return root; | ||
return root!; | ||
} | ||
protected select(...selectors: string[]) { | ||
const { ensuredRoot } = this; | ||
if (!(ensuredRoot instanceof Element)) { | ||
throw new Error(`root is not an Element.`); | ||
protected select(...selectors: string[]): Element | null { | ||
const { root } = this; | ||
if (!(root instanceof Element)) { | ||
return null; | ||
} | ||
return selectDom(ensuredRoot)(...selectors); | ||
return selectDom(root)(...selectors); | ||
} | ||
protected ensuredSelect(...selectors: string[]) { | ||
protected ensuredSelect(...selectors: string[]): Element { | ||
const element = this.select(...selectors); | ||
@@ -36,0 +36,0 @@ if (element === null) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29149
346
Updatedtest-drive@^1.1.1