How to use the testdouble/dist/testdouble.when function in testdouble

To help you get started, we’ve selected a few testdouble examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paypal / paypal-card-components / test / component.js View on Github external
}
      },
      links: []
    };
    btClientCreate = td.replace(btClient, 'create');
    contingencyFlowStart = td.replace(contingencyFlow, 'start');

    fakeHostedFieldsInstance = td.object([ 'tokenize' ]);
    td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object))).thenResolve(fakeTokenizationPayload);
    hostedFieldsCreate = td.replace(hostedFields, 'create');

    fakeBtClient = {
      getConfiguration: (conf) => conf
    };

    td.when(hostedFieldsCreate(td.matchers.isA(Object))).thenResolve(fakeHostedFieldsInstance);
    td.when(btClientCreate(td.matchers.isA(Object))).thenResolve(fakeBtClient);

    const button = document.createElement('button');
    button.id = 'button';

    // $FlowFixMe
    document.body.appendChild(button);
  });
github paypal / paypal-card-components / test / contingency-flow.js View on Github external
beforeEach(() => {
    fakeContingencyInit = td.replace(contingencyFlow.contingency, 'Component');
    fakeContingencyComponentRender = td.func();
    td.when(fakeContingencyInit(), { ignoreExtraArgs: true }).thenReturn({
      render: fakeContingencyComponentRender
    });
  });
github paypal / paypal-card-components / test / component.js View on Github external
method: 'GET'
          },
          {
            rel:    'information_link',
            href:   'https://developer.paypal.com/docs/api/errors/#contingency',
            method: 'GET'
          },
          {
            rel:    'cancel',
            href:   'https://api.paypal.com/v1/checkout/orders/21E005655U660730L',
            method: 'DELETE'
          }
        ]
      };

      td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object)))
        .thenReject(error);

      td.when(contingencyFlow.start(expectedUrl)).thenReject();

      return HostedFields.render(renderOptions, '#button').then((handler) => {
        return handler.submit().then(rejectIfResolves).catch(() => {
          td.verify(contingencyFlowStart(expectedUrl));
        });
      });
    });
  });
github paypal / paypal-card-components / test / component.js View on Github external
it('rejects with an error if braintree-web.client errors out', () => {
    const error = new Error('Some BT Web client Error');

    td.when(btClientCreate(td.matchers.isA(Object))).thenReject(error);

    return HostedFields.render(renderOptions, '#button').then(rejectIfResolves).catch((err) => {
      td.verify(hostedFieldsCreate(td.matchers.anything()), {
        times: 0
      });

      assert.equal(err, error);
    });
  });
github paypal / paypal-card-components / test / component.js View on Github external
HostedFields.render(renderOptions, '#button2').then((handler) => {
      const tokenizationData = {
        foo: 'bar'
      };
      td.replace(handler, 'submit');
      td.when(handler.submit()).thenResolve(tokenizationData);
      btn.click();

      setTimeout(() => {
        td.verify(renderOptions.onApprove(tokenizationData));
        done();
      }, 100);
    }).catch(done);
  });
github paypal / paypal-card-components / test / component.js View on Github external
HostedFields.render(renderOptions, '#button2').then((handler) => {
      const error = new Error('error');
      td.replace(handler, 'submit');
      td.when(handler.submit()).thenReject(error);
      btn.click();

      setTimeout(() => {
        td.verify(renderOptions.onError(error));
        done();
      }, 100);
    }).catch(done);
  });
github paypal / paypal-card-components / test / component.js View on Github external
rel:    'information_link',
            href:   'https://developer.paypal.com/docs/api/errors/#contingency',
            method: 'GET'
          },
          {
            rel:    'cancel',
            href:   'https://api.paypal.com/v1/checkout/orders/21E005655U660730L',
            method: 'DELETE'
          }
        ]
      };

      td.when(fakeHostedFieldsInstance.tokenize(td.matchers.isA(Object)))
        .thenReject(error);

      td.when(contingencyFlow.start(expectedUrl)).thenReject();

      return HostedFields.render(renderOptions, '#button').then((handler) => {
        return handler.submit().then(rejectIfResolves).catch(() => {
          td.verify(contingencyFlowStart(expectedUrl));
        });
      });
    });
  });
github paypal / paypal-card-components / test / component.js View on Github external
beforeEach(() => {
      button = document.createElement('button');
      button.id = 'button';
      renderOptions.createOrder = td.function();


      if (document.body) {
        document.body.appendChild(button);
      }

      td.when(renderOptions.createOrder()).thenReturn(orderId);
    });