Shob S
05/20/2025, 3:10 PMAnthony OConnor
05/20/2025, 3:45 PMShawn Talbert
05/20/2025, 5:25 PMAnthony OConnor
05/20/2025, 5:26 PMShawn Talbert
05/20/2025, 5:28 PMAnthony OConnor
05/20/2025, 5:28 PMShawn Talbert
05/20/2025, 5:29 PMcreece
05/20/2025, 5:35 PMShawn Talbert
05/20/2025, 7:22 PMShawn Talbert
05/20/2025, 7:22 PMcreece
05/20/2025, 7:28 PMcreece
05/20/2025, 7:28 PMShawn Talbert
05/20/2025, 7:34 PM.save()
on it and want a unit test to ensure the .save() happens, or at a minimum they have to mock that .save()
so the test including such a line of code can execute.Shawn Talbert
05/20/2025, 7:35 PMrecord.setValue()
without mocking record.setValue()
lest it explode if run in a unit test.Shawn Talbert
05/20/2025, 7:37 PMN/*
modules within.Shawn Talbert
05/20/2025, 7:38 PMN/record
so leapfrogs that whole problem.Shawn Talbert
05/20/2025, 7:39 PMcreece
05/20/2025, 7:40 PMcreece
05/20/2025, 7:41 PMShawn Talbert
05/20/2025, 7:41 PMshouldSave()
method must not call any other netsuite APIs (including getValue/setValue/sublist/subrecord) else you're back in mocking land.creece
05/20/2025, 7:42 PMcreece
05/20/2025, 7:42 PMShawn Talbert
05/20/2025, 7:47 PMsave()
works as expected (we're not testing NetSuite's code) you very certainly can have business logic that depending on rules either decides to save()
or not save.... having a unit test that save()
was or was not called is useful, and imho simpler/cleaner than a separate shouldSave()
function in isolationShawn Talbert
05/20/2025, 7:48 PMtest('setCustomerCompanyName', function () {
// create a 'stub' Customer with only a few fields populated (those fields we need for the test)
const x = stub<Customer>({
firstname: 'joe',
lastname: 'schmoe',
save: jest.fn()
})
const result = sut.createCompanyName(x)
expect(result.companyname).toBeTruthy()
expect(result.companyname).toEqual('joe schmoe')
expect(x.save).toHaveBeenCalled()
})
creece
05/20/2025, 7:49 PMcreece
05/20/2025, 7:49 PMShawn Talbert
05/20/2025, 7:50 PMcreateCompanyName()
implemenation:creece
05/20/2025, 7:50 PMShawn Talbert
05/20/2025, 7:51 PM${c.firstname} ${c.lastname}
c.save() // see unit tests for inspecting calls to NSDAL methods like save()
return c
}creece
05/20/2025, 7:51 PMShawn Talbert
05/20/2025, 7:53 PMcreece
05/20/2025, 7:53 PMcreece
05/20/2025, 7:54 PMShawn Talbert
05/20/2025, 7:55 PMcreece
05/20/2025, 7:56 PMcreece
05/20/2025, 7:57 PMcreece
05/20/2025, 7:58 PMShawn Talbert
05/20/2025, 7:58 PMcreece
05/20/2025, 8:00 PMShawn Talbert
05/20/2025, 8:00 PMgetValue(), setValue()
and similar, and also without any additional overhead like functions written just to support testability.creece
05/20/2025, 8:00 PMcreece
05/20/2025, 8:01 PMcreece
05/20/2025, 8:03 PMShawn Talbert
05/20/2025, 8:03 PMcreece
05/20/2025, 8:03 PMShob S
05/22/2025, 2:17 PM