Injecting Mock Data in QBO3 Objects

What Are Mock Objects?

For a good overview of Mock Objects, please read:

Why Do We Need Mock Data In QBO3?

The use case that ultimately prompted this functionality is the need to test ImportForms that rely on 3rd party data, without depending on the 3rd party.

  • An ImportForm might be driven by data from a Fiserv API call. 
    • A test environment might not have credentials configured to access Fiserv.
    • If a test case requires specific data, Fiserv might not have a relevant entry.
Mock data allows us to define test data, intercept an outgoing Request, and return the test data.

Code Sample

Mock data is only available in the context of Jasmine tests, or Theme.ashx/Specs.

In our tests, we have to define test data in a jasmine.mockData object.
  • The test data follows this pattern:
    • Classname
      • Method
        • Test Data
Abstract example:
jasmine.mockData = {
    ClassName: {
        Method: {
            TestItem1: TestValue1

If one needed to test against a Fiserv entry in which the USState = 'CA' and LienPosition='002', the mock data object would be:

jasmine.mockData = {
    Loan: {
        Fiserv: {
            USState: 'CA',
            LienPosition: '002'

 In this case, any call to Loan/Fiserv would return the test data defined above. 

This is, in a rough way, an instantiation of the Dependency Injection pattern, which is critical for robust testing: