Skip to content

Instantly share code, notes, and snippets.

@rebolyte
Last active July 28, 2016 19:47
Show Gist options
  • Save rebolyte/a58d113988a2624ca84203839ba47008 to your computer and use it in GitHub Desktop.
Save rebolyte/a58d113988a2624ca84203839ba47008 to your computer and use it in GitHub Desktop.
Testing Jasmine spies
it('can call a callback that is passed', function () {
let callback = jasmine.createSpy('callback function');
let putItem = jasmine.createSpy().and.callFake((params, cb) => {
expect(params.id).not.toBeUndefined();
cb('done');
});
putItem({ id: 1 }, callback);
expect(callback).toHaveBeenCalledWith('done');
});
describe('spying', () => {
it('calls callback passed to it', function () {
let data = {
Item: {
CameraID: '213c',
LocationName: 'Testing spies'
}
};
let docClient = {
get(params, cb) {
expect(params.TableName).toEqual(jasmine.any(String));
expect(params.Key.HashKey).toEqual(jasmine.any(String));
cb(null, data);
}
};
spyOn(docClient, 'get').and.callThrough();
let params = {
TableName: 'testTable',
Key: {
HashKey: 'hash'
}
};
let callback = jasmine.createSpy();
docClient.get(params, callback);
expect(callback).toHaveBeenCalledWith(null, data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment