but i need to understand more about how to test Us...
# sdf
m
but i need to understand more about how to test User Event scripts for instance
b
not really specific to jest, but the basics of testing is that you call the function you want to test with the parameters you want to test it with
m
i know that it is just that there are only a few samples and I cannot understand how to properly use mocks there
b
preferably you dont start at the entry points functions, its a rather large surface area for a test
m
it is
b
but you are creating mocks for the netsuite modules because at some point, the parameters you pass in for your function will try to use the netsuite modules
and those netsuite modules dont exist
so the mocks make a fake object that has functions and properties that you setup beforehand
m
i got that
b
now that the basics are out of the way
what script are you trying to test
m
you said something that could be the key, i used mockito before with spring boot andwhen doing integration tests i just ran my code and create mocks for objects i wanted to mock up the entry data or rerturns
in NS my idea was that when i create a UE script for instance
letโ€™s say that it gets data from context.newRecord and creates a JSON payload to send outside
i wanted to mock the entry of the Record object with pre set data and then check if the JSON object has been created correctly
but i was running the afterSubmit function
locally but got lost on how to actually interact with fake N(modules
i saw a couple of samples one using suitelet but did not get the gist of it to adapt it to my sample
you said preferably you dont start at the entry points functions, its a rather large surface area for a tes
and maybe this is what i am doing wrong
b
it really depends on how complex your code gets
on a more technical level, its depends on branching
m
i should try to test partially although my main idea is to get used to a methodology by which every time a finish a UE for instance, i force myself to write integration tests for all scenarios to make sure it works
what do you mean?
b
when doing unit tests, you want to test small functions
that do specific things
m
i know
b
and ignore branches that occur when you put those functions together
m
yes
b
if you start at the entrypoint, you are testing everything
its more of an integration test
m
i see
it is an integration test what i had in mind from start
but i see your point with what it is provided
s
imho the value of such an integration test is dubious - you'll likely have to mock so much as to diminish the actual value of the test.
๐Ÿ‘ 1
๐Ÿ’ฏ 1
m
which could make more sense for unit tests
s
FWIW, unit testing with NFT is easier because it needs much less SuiteScript API mocking.
m
i agree and. this is why i said that the key was what @battk said before
s
with NFT your functions tend to manipulate plain objects, which are easy to setup in the test.
m
i should probably focus on unit tests rather than go for the entry function
๐Ÿ‘ 1
and mock less objects
appreciate your feedback guys
b
probably not really mock less objects
but mock less at the same time
m
yes that is what i meant
divide and conquer
c
Alternatively, separate the business logic from netsuite specific logic. You don't have to mock anything netsute then.
m
thanks i will do that