Hi, Does anyone have experience with unit-testing ...
# suitescript
s
Hi, Does anyone have experience with unit-testing in NetSuite? I would like to mock a record instance with values, so I can test code that gets and sets values on many fields. I have a prosses in mined that would work like this:
Copy code
data = {
    'field_id': 'field value',
};
record = Record(data);
cost field = record.getValue({ fieldId: 'field_id', });

field == 'field value' // == true
The netsuite-suitecloud-sdk doesn't provide this functionality. Does anyone have any ideas? Thank You!
b
c
I wouldn't consider that a good test though. You're testing netsuite and not your logic which isn't a worthwhile test IMO. If you have business logic you implemented, i'd test that but simply setting a field and making sure netsuite actually sets it would be outside the scope of a valid test.
👍 1
s
NFT has some examples of working unit tests.
c
are you using Jest in NFT?
I haven't written unit tests for Netsuite code in years
s
yeah, NFT unit tests are jest based.
s
i'm new with unit testing in js. I'm not using NFT
c
Jest is what i built my old stuff in it's def the way to go
s
Thanks! ill look in to NFT
c
The process should be pretty similar even if you don't want to use NFT.
s
I'm not trying to test the functionality of NetSuite. rather I'm getting in my code may values from NetSuite and doing some logic based on these values. I would like to create a global mock implementation that i can export to different test scripts. but i'm not sure how to go about it.
c
I'd have a function that takes in those values as native data types and then test that business logic and not the getting/setting of NetSuite. I get what you're trying to do just making the tests easier/more worthwhile.
✔️ 1
e
Additional examples of functional unit tests: https://gitlab.com/stoicsoftware/feature-flags/-/tree/main/__tests__
Also here's an alternate module for mocking NetSuite modules: https://github.com/KyleJonesWinsted/suitecloud-unit-testing-stubs