Closed darktasevski closed 3 years ago
Great question! By default, we load all of the source/
scripts into scope in your test cases, so you can run them directly. However, we don't do that with the components/
directory, because component scope is a bit more complicated, so we operate under the assumption that any .brs
files in components/
will be pulled into a component before testing.
That being said, there are a couple of ways to test these files:
ComponentUtils.brs
. This is usually a good idea if this script is only being pulled into one or two components, and is coupled to the behavior of those components.tests/ComponentUtils.test.xml
. Then you can: expose the functions on the interface
, instantiate the component, and use callFunc
in your test cases. (Of course, you'd want to make sure you don't bundle these components with your application when you deploy it!)And if you have any recommendations for an easier pattern, feel free to drop them here 😄
callFunc
suggestion sounds good, should be easy to filter those out when creating a prod bundle, I'll give it a try these days, thank you.
May I suggest adding this to the documentation? I see that you're working on improving docs lately but it's not really clear how the test suite scope is working and what are limitations. Thanks!
Update: Tried this approach, and it's working like a charm. Thank you!
Yep, we definitely want to add this to the documentation, as it's a very common question -- we'll keep this issue open until we've added it 👍
So, I wrote a few tests and put them in the
source/tests/
directory. All is working fine, but after that, I tried to write tests for some util functions that are inside the components directory, and I'm getting errors.Looks like Roca is not detecting the functions declared inside
ComponentUtils.brs
file, which somehow makes sense, but is there any way I can import that file to the test suite so that I can test the functions from it?This is an example of how dir structure I've tried to set up tests