Skip to content

Commit bf106d9

Browse files
Removed old dom related test utils
1 parent 6e84c8b commit bf106d9

File tree

6 files changed

+28
-446
lines changed

6 files changed

+28
-446
lines changed

test-dom/src/main/scala/scommons/react/test/dom/raw/ReactTestUtils.scala

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import scala.scalajs.js.annotation.JSImport
1010
@js.native
1111
object ReactTestUtils extends js.Object {
1212

13-
type Instance = js.Object with js.Dynamic
14-
1513
/**
1614
* @see [[scommons.react.test.dom.raw.Simulate]]
1715
*/
@@ -22,76 +20,4 @@ object ReactTestUtils extends js.Object {
2220
* This makes your test run closer to how React works in the browser.
2321
*/
2422
def act(block: js.Function0[Unit]): Unit = js.native
25-
26-
/**
27-
* Render a React element into a detached DOM node in the document. This function requires a DOM.
28-
*/
29-
def renderIntoDocument(element: js.Object): Instance = js.native
30-
31-
/**
32-
* Returns `true` if `element` is any React element.
33-
*/
34-
def isElement(element: js.Any): Boolean = js.native
35-
36-
/**
37-
* Returns `true` if `element` is a React element whose type is of a React `componentClass`.
38-
*/
39-
def isElementOfType(element: js.Any, componentClass: js.Object): Boolean = js.native
40-
41-
/**
42-
* Returns `true` if `instance` is a DOM component (such as a `div` or `span`).
43-
*/
44-
def isDOMComponent(instance: js.Any): Boolean = js.native
45-
46-
/**
47-
* Returns `true` if `instance` is a user-defined component, such as a class or a function.
48-
*/
49-
def isCompositeComponent(instance: js.Any): Boolean = js.native
50-
51-
/**
52-
* Returns `true` if `instance` is a component whose type is of a React componentClass.
53-
*/
54-
def isCompositeComponentWithType(instance: js.Any, componentClass: js.Object): Boolean = js.native
55-
56-
/**
57-
* Traverse all components in `tree` and accumulate all components where `test(component)` is `true`.
58-
* This is not that useful on its own, but it's used as a primitive for other test utils.
59-
*/
60-
def findAllInRenderedTree(tree: js.Any,
61-
test: js.Function1[Instance, Boolean]): js.Array[Instance] = js.native
62-
63-
/**
64-
* Finds all DOM elements of components in the rendered tree that are DOM components with the class name
65-
* matching `className`.
66-
*/
67-
def scryRenderedDOMComponentsWithClass(tree: js.Any, className: String): js.Array[Instance] = js.native
68-
69-
/**
70-
* Like `scryRenderedDOMComponentsWithClass()` but expects there to be one result, and returns that one result,
71-
* or throws exception if there is any other number of matches besides one.
72-
*/
73-
def findRenderedDOMComponentWithClass(tree: js.Any, className: String): Instance = js.native
74-
75-
/**
76-
* Finds all DOM elements of components in the rendered tree that are DOM components with the tag name
77-
* matching `tagName`.
78-
*/
79-
def scryRenderedDOMComponentsWithTag(tree: js.Any, tagName: String): js.Array[Instance] = js.native
80-
81-
/**
82-
* Like `scryRenderedDOMComponentsWithTag()` but expects there to be one result, and returns that one result,
83-
* or throws exception if there is any other number of matches besides one.
84-
*/
85-
def findRenderedDOMComponentWithTag(tree: js.Any, tagName: String): Instance = js.native
86-
87-
/**
88-
* Finds all instances of components with type equal to `componentClass`.
89-
*/
90-
def scryRenderedComponentsWithType(tree: js.Any, componentClass: js.Object): js.Array[Instance] = js.native
91-
92-
/**
93-
* Same as `scryRenderedComponentsWithType()` but expects there to be one result and returns that one result,
94-
* or throws exception if there is any other number of matches besides one.
95-
*/
96-
def findRenderedComponentWithType(tree: js.Any, componentClass: js.Object): Instance = js.native
9723
}

test-dom/src/main/scala/scommons/react/test/dom/raw/TestReactDOM.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import scala.scalajs.js.annotation.JSImport
99
@JSImport("react-dom", JSImport.Namespace)
1010
object TestReactDOM extends js.Object {
1111

12-
def findDOMNode(component: js.Any): Node = js.native
13-
1412
/**
1513
* Remove a mounted React component from the DOM and clean up its event handlers and state.
1614
*

test-dom/src/main/scala/scommons/react/test/dom/util/TestDOMUtils.scala

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import io.github.shogowada.statictags
66
import org.scalajs.dom
77
import org.scalajs.dom._
88
import org.scalatest.{BeforeAndAfterEach, Matchers, Suite}
9-
import scommons.react.UiComponent
10-
import scommons.react.test.dom.raw.ReactTestUtils._
11-
import scommons.react.test.dom.raw.{ReactTestUtils, Simulate, TestReactDOM}
9+
import scommons.react.test.dom.raw.{ReactTestUtils, Simulate}
1210

1311
import scala.scalajs.js
1412

@@ -48,26 +46,6 @@ trait TestDOMUtils extends Suite with Matchers with BeforeAndAfterEach {
4846
js.Dynamic.newInstance(tag.constructor)(args: _*).asInstanceOf[T]
4947
}
5048

51-
//////////////////////////////////////////////////////////////////////////////
52-
//START of deprecated methods section:
53-
// use domRender(...) and assert domContainer
54-
55-
def renderIntoDocument(element: ReactElement): Instance = ReactTestUtils.renderIntoDocument(element)
56-
57-
def findRenderedComponentProps[T](tree: Instance, searchComp: UiComponent[T]): T = {
58-
getComponentProps[T](findRenderedComponentWithType(tree, searchComp.apply()))
59-
}
60-
61-
private def getComponentProps[T](component: Instance): T = component.props.wrapped.asInstanceOf[T]
62-
63-
def findReactElement(component: js.Any): dom.Element = asElement(TestReactDOM.findDOMNode(component))
64-
65-
//END of deprecated methods section
66-
//////////////////////////////////////////////////////////////////////////////
67-
68-
69-
private def asElement(node: Node): dom.Element = node.asInstanceOf[dom.Element]
70-
7149
def assertDOMElement(result: dom.Element, expected: statictags.Element): Unit = {
7250
assertElement(TestDOMPath(result, result), expected)
7351
}
@@ -184,7 +162,7 @@ trait TestDOMUtils extends Suite with Matchers with BeforeAndAfterEach {
184162
}
185163

186164
for (i <- result.indices) {
187-
assertElement(path.at(asElement(result(i))), i)
165+
assertElement(path.at(result(i).asInstanceOf[dom.Element]), i)
188166
}
189167
}
190168

0 commit comments

Comments
 (0)