How to use the spyOn function from aws-sdk

Find comprehensive JavaScript aws-sdk.spyOn code examples handpicked from public code repositorys.

57
58
59
60
61
62
63
64
65
66

describe('getting things', () => {
  afterEach(() => AWS.clearAllMocks());

  it('returns the thing', async () => {
    const get = AWS.spyOn('S3', 'getObject').mockReturnValue({
      promise: () => Promise.resolve('foo')
    });

    const thing = await getThing();
fork icon3
star icon19
watch icon79

+ 11 other calls in file

36
37
38
39
40
41
42
43
44
  expect(AWS.S3).toHaveBeenCalledWith({ region: 'ab-cdef-1' });
  expect(get).toHaveBeenCalledWith({ Bucket: 'my', Key: 'thing' });
});

it('clears mocks', async () => {
  AWS.spyOn('S3', 'putObject');

  const s3 = new AWS.S3();
  expect(jest.isMockFunction(s3.putObject)).toEqual(true);
fork icon3
star icon19
watch icon79

+ 19 other calls in file

51
52
53
54
55
56
57
58
59
60
  }, 0)
  return self
}

const baseGet = () =>
  AWS.spyOn('S3', 'getObject').mockImplementation(baseGetImplementation)

afterEach(() => {
  spyLog.mockClear()
  spyError.mockClear()
fork icon2
star icon10
watch icon3

+ 3 other calls in file