コード例 #1
0
describe('getShortUrl saga', () => {
  const action = getShortUrlRequest('test1Url.com');
  let apiCall = null;
  const generator = getShortUrl(action);

  const createApiCall = genNext;
  it('should create api call to get whitelabels', () => {
    const url = `${config.API_URL}/s`;
    const params = { url: action.originUrl };

    apiCall = createApiCall(generator).value;

    const apiClientStub = { post: expect.createSpy() };

    apiCall(apiClientStub);

    expect(apiClientStub.post).toHaveBeenCalled();
    expect(apiClientStub.post).toHaveBeenCalledWith(url, params);
  });

  const forkApiRequest = genNext;
  it('should call apiRequest saga', () => {
    const nextValue = forkApiRequest(generator).value;
    const expectedValue = fork(apiRequest, apiCall, GET_SHORT_URL, action);

    expect(nextValue).toEqual(expectedValue);
  });

});
コード例 #2
0
ファイル: shortener.spec.js プロジェクト: jsdmc/url-shortener
  it('getShortUrlRequest should dispatch GET_SHORT_URL.REQUEST', () => {
    const testUrl = 'testUrl';
    const actualValue = getShortUrlRequest(testUrl);

    const expectedValue = {
      type: GET_SHORT_URL.REQUEST,
      originUrl: testUrl,
    };

    expect(actualValue).toEqual(expectedValue);
  });