DomComponentFilter is a ComponentFilter for Dom components in the React tree. Originally Dom components were similar to React components in that they had props and state on them. As of 0.15 this will change, so we need to make sure that DomComponents can only access the things that they have access to.
ComponentFilter = require("./ComponentFilter.litcoffee")
class DomComponentFilter extends ComponentFilter
constructor: (@value, @util, @testers, @messages) ->
super(@value, @util, @testers, @messages)
cssClass: (cssClass) ->
# FIXME: This matches substrings. We should split on
# spaces and match if any are equal. However, if we do
# that we need a way to match collections of cssClasses.
@bind (nodes) =>
match = (a, b) ->
return false if !b?
b.indexOf(a) != -1
if nodes?.length
matched = (node for node in nodes when match(cssClass, node.className))
else
matched = []
messages = [
"Expected to find DOM node with class #{cssClass}, but it was not there."
"Expected not to find DOM node with class #{cssClass}, but there #{@was(matched.length)}."
]
if matched.length > 0
@return(matched, messages)
else
@return(null, messages)
text: (string) ->
@bind (nodes) =>
match = (a, b) ->
return false if !b?
b.indexOf(a) != -1
if nodes?.length
matched = (node for node in nodes when match(string, node.textContent))
else
matched = []
messages = [
"Expected to find DOM node containing text #{string}, but it was not there."
"Expected not to find DOM node containing text #{string}, but there #{@was(matched.length)}."
]
if matched.length > 0
@return(matched, messages)
else
@return(null, messages)
Export our filter from this file.
module.exports = DomComponentFilter