Might be a little less setup?
Something like (maybe need to split up or move arguments around):
Basically always unpad, trim
const babel = require("babel-core");
const unpad = require("utils/unpad");
export function transform(source, plugin, options) {
return babel.transform(unpad(source), {
plugins: [[plugin, options]],
}).code.trim();
}
export function expectTransform(source, expected, plugin, options = {}) {
return expect(transform(source, plugin, options)).toBe(unpad(expected));
}
Good idea.
Also, since we are always checking transformed input to static output, it would make sense to add toMatchSnapshot feature of jest, and we don't have to maintain a separate expected value at all.
I'm not sure if we can use it for any content - though in the docs it says React Component.
cc @cpojer?
Jest snapshots work with any serializable value, we just haven't documented it yet. This is actually the ideal use case for snapshots and should allow you guys to move much faster. Also cc @kyldvs who loves using it for strings.
Added in #606 . :)
Most helpful comment
Jest snapshots work with any serializable value, we just haven't documented it yet. This is actually the ideal use case for snapshots and should allow you guys to move much faster. Also cc @kyldvs who loves using it for strings.