Last active
July 28, 2016 19:47
-
-
Save rebolyte/a58d113988a2624ca84203839ba47008 to your computer and use it in GitHub Desktop.
Testing Jasmine spies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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