Closed leozilla closed 7 years ago
Hi. I don't want to start adding Chai plugins to PostmanBDD, since it will bloat PostmanBDD with extra stuff that most people don't need. But you can easily add the Chai-Subset plugin (or any other Chai plugin) yourself.
1. Download the file
Any JavaScript file that's hosted anywhere online (such as GitHub) can be loaded in Postman by simply adding a GET
request to download the JavaScript file, exactly the same way that you downloaded PostmanBDD. For example, to download Chai-Subset, you'd just need to add a GET
request with the following URL:
https://cdn.rawgit.com/debitoor/chai-subset/96755808/lib/chai-subset.js
2. Store the script in a variable Once the JavaScript file has been downloaded, you need to store it in a variable so you can access it from other Postman requests. Again, this is exactly the same as when you "installed" PostmanBDD. So, to store Chai-Subset in a variable, you'd do something like this:
postman.setGlobalVariable('chaiSubset', responseBody);
3. Load the script whenever it's needed
Once you've stored the script in a variable, it's available to use wherever you need it. You can "load" the script in any request by using the JavaScript eval()
function, just like you did when you loaded PostmanBDD. So, to load Chai-Subset, you'd just do this:
// Load PostmanBDD first, since it includes Chai.js
eval(globals.postmanBDD);
// Load Chai-Subset next, since it depends on Chai.js
eval(globals.chaiSubset);
// Now you can use PostmanBDD and Chai-Subset
describe('My test suite', () => {
it('should return the expected JSON data', () => {
response.body.should.containSubset({
firstName: 'John',
lastName: 'Doe',
});
});
});
Thanks man, you are super helpfull!
Is it possible to include the chai-subset module (http://chaijs.com/plugins/chai-subset/)?
I am new to javascript tooling so I am pretty lost.