-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented history to record all calls to the mock (#124)
* implemented history to record all calls to the mock * modified mock reset function to resets handlers and history, implemented resetHandlers to reset only handlers
- Loading branch information
1 parent
6a187dc
commit 2eb55cc
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var axios = require('axios'); | ||
var expect = require('chai').expect; | ||
|
||
var MockAdapter = require('../src'); | ||
|
||
describe('MockAdapter history', function() { | ||
var instance; | ||
var mock; | ||
|
||
beforeEach(function() { | ||
instance = axios.create(); | ||
mock = new MockAdapter(instance); | ||
}); | ||
|
||
it('initializes empty history for each http method', function() { | ||
expect(mock.history['get']).to.eql([]); | ||
expect(mock.history['post']).to.eql([]); | ||
expect(mock.history['put']).to.eql([]); | ||
}); | ||
|
||
it('records the axios config each time the handler is invoked', function() { | ||
mock.onAny('/foo').reply(200); | ||
|
||
return instance | ||
.get('/foo') | ||
.then(function(response) { | ||
expect(mock.history.get.length).to.equal(1); | ||
expect(mock.history.get[0].method).to.equal('get'); | ||
expect(mock.history.get[0].url).to.equal('/foo'); | ||
}); | ||
}); | ||
|
||
it('reset history should reset all history', function() { | ||
mock.onAny('/foo').reply(200); | ||
|
||
return instance | ||
.get('/foo') | ||
.then(function(response) { | ||
mock.resetHistory(); | ||
expect(mock.history['get']).to.eql([]); | ||
}); | ||
}); | ||
}); |