Hi. does anyone know how to write unit tests for S...
# suitescript
s
Hi. does anyone know how to write unit tests for SS2.0 code?
b
very similar to other unit tests
except that you will be mocking netsuite's api
c
or alternatively, separate your business logic from actual netsuite logic and you can unit test easily.. you don't REALLY need to mock netsuite api as you shouldn't be testing netsuite but rather your logic on the data FROM netsuite
its a totally different way of writing netsuite code to work that way.. or write in some higher abstraction like typescript but you're still mocking a lot more than you really need to
s
Thanks @battk and @creece. Actually I am new to both SS2.0 and unit testing. Normally we just upload our files to NetSuite and it just recognizes the "define" structures. Could you please point me how i can trigger the scripts and how will my local environment know what is "define".
c
you'd have to find some kind of unit testing framework like mocha/should and follow their patterns
unit tests would be 100% outside of netsuite
there IS a help article on unit testing w/ a sample as well
a
@creece NetSuite does not have an officially supported Unit Testing thing?
Found it...
Karma
On the Help: Project Sample: SuiteScript 2.0 Unit Testing
c
the more you can decouple your logic from netsuite logic the better your tests are going to be
then you dont need to mock netsuite methods
im pretty interested in this kind of stuff if you find a better way lemme know