Data generation is a key aspect of unit testing. Without good data generation, unit testing can be less than productive. To fill that gap, Fonteva created data generators that will allow you to generate Salesforce data – both standard and custom objects.

useDataGenerators - (line 24 below) - You can build your own data generators so that you can provide any data you want. If you want to use several data generators, provide a comma-separated list of those generators. Fonteva uses chance.js to generate data. (See You can also provide datasets using a seed. (See


const {
} = require('mocha-fonteva-data-generator');


The following is an example of setting a prefix value for attendee for the inject() method (fixed:{contactID:990}). It calls the test method with the Attendee object.



The following randomly generates 1-5 attendees with random data., all with random data, It then calls your test method with an array of attendees. Even if you only create one, it will still send an array of objects.

@inject([LTEAttendee, 1, 5])

Example data generator

The example generator will generate an event Attendee object. This includes all the information that is required for us to test the event by the Attendee object, including Salesforce IDs generated based on custom work done to ensure the IDs match the format Salesforce provides. You can override and build your own methods to create test data. You can generate every object that Fonteva has in their system, or you can create your own. 

If you want to generate an attendee and override a value without actually generating it, you can do the following:

  • DEFAULT_PARAMS - (line 4 below) Contains any overrides that you want to send that are part of the data generator instantiation. For example, 

    {contactId:990} or {isInvitationOnly: false}


    @inject(LTEAttendee({fixed:{contactId:990}}), LTEEvent({fixed: {isInvitationOnly: false}}), LTEUser({fixed:{contactId:990}}), true, false)
  • makeNullItems - (line 4) You can set as null, for example, 50% of the time.


  • generateAttendee() (line 20) - Generates the data. It uses a library called chance.js that allows for the generation of random data. In your test code, you don't need to call any methods. The constructor is called by default, resulting in the generate method getting automatically called.   
chance generates a seed. After it is generated, you can provide chance with this same seed. This seed will generate the same data every time the test runs. This allows you to create data sets for different scenarios.  





Previous: Framework Adapters     |     Next: Calling Test Methods