jackmellis / mock-http Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
i.e.
http.when(/api\/({\d+})/).call(config => {
var id = config.match[0];
return { data : id };
});
http.when('/api/1').return({ data : 'foo' });
http.expect(/\/api\/\d+/).next();
http.get('api/1').then(response => {response.data === 'foo'});
so basically you can intercept a request but still return the original data.
Perhaps we should make the callbacks chainable i.e. .call(spy).stop()
or .call(spy).next()
Firstly, the find matching when method should return an array of when's, so we can easily get the next one.
Secondly, callback should also be an array, so we can loop through an call all of the callbacks.
http.when('/api/success').status(200).data('ok');
http.when('/api/error').status(500).reject('broked');
response = await http.get('/api/success'); // { status : 200, data : 'ok' }
failure = await http.get('/api/error'); // Error { status : 500, message : 'broked' }
data and body should accept a function as well. It no status, data adds a default status of 200.
Configure the data transformer:
http.transformResponse = (status, data) => ({status, body : data});
I think the only thing it uses it for it $promise. Could get around this by saying if jpex ecists and $promise exists, use it, otherwise just default to global Promise class
http('/api/some/url', { /* config */ });
when calling http.expect('/api', 3)
it assumes this means a method of /api and a url of 3. It should check if count is undefined and url is a number, then shift all values across one.
So you can say this test expects this request, then after the test call assert which checks that all expected calls have been made
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.