ft-webplatform/test/unit/test-utils.js
Martin Donnelly 76920442b1 init
2017-09-28 13:04:16 +01:00

25 lines
792 B
JavaScript

/**
* Test Utils for reducers
*
* E.g. setJSONFixture('src/components/products/performance/ft-discrete-returns/lib/etf/mock-new-state-out.fixture.json', newState);
*/
/**
* synchronously save JSON fixture file
* @parameter {string} filename eg /components/products/pricing-distribution/ft-pricing-distribution/lib/gw/mock-new-state-out.fixture.json
* @parameter {Object} obj file to stringify and store in file
*/
export function setJSONFixture(filename, obj) {
const fs = require('fs');
fs.writeFileSync(filename, JSON.stringify(obj, null, ' '));
}
/**
* edit a object to remove undefineds and make flat
* @parameter {Object} obj file to stringify and store in file
* @return {Object}
*/
export function removeUndefineds(obj) {
return JSON.parse(JSON.stringify(obj));
}