Mocking Entry Point Functions in Unit Tests
A simple starting point for writing tests could be verifying the entry point functions. Each entry point function has required and optional parameters. You can format your test to ensure the parameters have the correct values and types. For more information about entry point functions, see SuiteScript 2.x Script Types and Entry Points.
The following example shows an object that represents a user event script that will run on the beforeLoad(context) entry point. The properties of this object are the assigned parameters of the beforeLoad entry point.
User Event Script example:
import runtime from 'N/runtime';
import Script from 'N/runtime/script';
import record from 'N/record';
import Record from 'N/record/instance';
const context = {
UserEventType: { // beforeLoad entry point properties
CREATE: 'CREATE',
EDIT: 'EDIT',
VIEW: 'VIEW'
}
};
describe('Mocking SuiteScript dependencies', () => {
it('Should do something', () => {
});
});
Suitelet Example:
import runtime from 'N/runtime';
import Script from 'N/runtime/script';
import record from 'N/record';
import Record from 'N/record/instance';
const scriptContext = {
request: {
parameters: {
record_id: 14,
sales_order_id: 325
}
};
describe('Mocking SuiteScript dependencies', () => {
it('Should do something', () => {
// test code goes here
});
});