Unit test in nerdpack

Unit test for nerdpack

Hi everyone, I’m working on a nerdpack but I had a question about how to do unit tests for the new relic api. I put an example

This is my component use nr1 sdk for get account id

The unit test would be something like:

But when I run the test obviously the library doesn’t recognize me

Is there any way to fix this?, or you are simply not contemplated yet?
Thanks for you answers

1 Like

@jgaona Sorry you’ve been waiting awhile for a response. This isn’t a category that is monitored by our support team. Going to reach out to @mfrederick to see if they can help.

Hi @JoiConverse I found the solution, soon I will upload an example in this same post to other people you could serve

1 Like

@jgaona YAY :star_struck: Thank you for being willing to share!

Hi @jgaona did you find any solution? I’m struggling with the same

Hi @dpena,

I was able to bypass the error by mocking the nr1 module via jest mocks.

More information here: Manual Mocks · Jest

Let me know how it goes

1 Like

Thanks @lucas88
I was able to do a mock for a single nr1 component, doing a nr1.jsfile in __mocks__directory. Although I was trying to mount a component that looks like this, and try to check if <MyComponent /> renders on App.js

// App.js

    <StackItem> <MyComponent/> </StackItem>

And my test is

const wrapper = mount(<App />);

but I got an error on StackItem

Not sure about what I should do…

Hi @jgaona, did you upload the example? Mocking the components as suggested in this thread by others works but does not go very far. Is there perhaps a way we can install the nr1 sdk into dev dependencies such that we can use them in our tests more naturally?