testMethod() (below) is the name you want to show in your test summaries, not the name of the method you're calling. inject() holds the values you want to inject into your test.

formFieldsHelperSpec.js

    @testMethod('updateFieldVisibilityByFieldInstance should skip field dependency')
    @inject({'f1': []}, '', {group: ''}, {}, {skipped: true})
JS
  • testMethod - The name you want to show in your test summaries.
  • inject - The values you want to inject into your test.

    EventRegistrationFlowDetailsControllerSpec.js

    @inject(LTEEvent, LTEUser, LTETicket, LTESalesOrder, true, true)
    
    JS

    In the example above, LTEEvent is using a data generator. You can generate one test data object, an array of objects, or, for example, a random number of objects between 35 and 75.

  • updateFieldVisibilityByFieldInstance() (below) - The actual test method you want to call.

You can have multiple testMethod() calls. Additionally, each testMethod() can have multiple inject() calls. This allows you to run the test method (updateFieldVisibilityByFieldInstance(), line 90, in this case) with different values so that you can test different scenarios.

The following example illustrates the complexity of the tests you can create:

formFieldsHelperSpec.js

    @testMethod('updateFieldVisibilityByFieldInstance should skip field dependency')
    @inject({'f1': []}, '', {group: ''}, {}, {skipped: true})

    @testMethod('updateFieldVisibilityByFieldInstance should skip field dependency due field mismatch or parameter checks')
    @inject({'f1': []}, '', {group: 'a', fieldId: 'f2'}, {}, {skipped: true})
    @inject({'f1': 'nonarray'}, '', {group: 'a', fieldId: 'f1'}, {}, {dependenciesMap: true})
    @inject({'f1': []}, '', {group: 'a', fieldId: 'f1', value: null}, {}, {dependenciesMap: true})
    @inject({'f1': []}, '', {group: 'a', fieldId: 'f1', value: undefined}, {}, {dependenciesMap: true})

    @testMethod('updateFieldVisibilityByFieldInstance should hide field')
    @inject({'f1': []}, '', {group: 'a', fieldId: 'f1', value: 'test'}, {}, {hide: true})
    @inject({'f1': []}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: ['f1']}, {hide: true, fieldType: 'picklist'})
    @inject({'f1': []}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: ['f1']}, {hide: true, fieldType: 'boolean'})
    @inject({'f1': []}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: ['f1']}, {hide: true, fieldType: 'boolean', nullCmp: true})

    @testMethod('updateFieldVisibilityByFieldInstance should not hide field if other dependencies exists')
    @inject({'f1': []}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: ['f1', 'f2']}, {hideUndef: true})

    @testMethod('updateFieldVisibilityByFieldInstance should show field')
    @inject({'f1': ['test']}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: ['f1', 'f2']}, {show: true})
    @inject({'f1': ['test']}, 'dep', {group: 'a', fieldId: 'f1', value: 'test'}, {dep: []}, {show: true})

    updateFieldVisibilityByFieldInstance(fieldDependencies, fieldId, args, dependenciesMap, result) {
        const component = result.nullCmp ? null : componentFactory({}, 'Framework:InputFields');
        const formCmp = componentFactory({
            dependenciesMap
        });
JS

In the code above, each testMethod() and associated inject() methods are a group of testing data that will be listed under a common heading (the testMethod() attribute) in your test summaries. Each inject() method will call the first method below the entire listing of testMethod() and inject() methods. In this example, updateFieldVisibilityByFieldInstance() will be called, and anything below will not.

If you want to call the inject method multiple times, instead of writing it out three times, you can generate these three objects (LTEEvent, LTESite, LTEUser) randomly by calling this method three times by using times(3).

@testMethod('should define what component should de built and build this component')
   @inject(LTEEvent, LTESite, LTEUser, true, true, true, true)
   .times(3)
   @inject(LTEEvent, LTESite, LTEUser, true, true, true, false)
   .times(3)
   @inject(LTEEvent, LTESite, LTEUser, true, true, false, true)
   .times(3)
JS

Previous: Data Generators     |     Next: Constructing a Test Method