@what-a-faka/obj-mutation
Version:
The Object Mutation
69 lines (68 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// import Mutation = require('./index');
var obj_mutation_1 = require("./obj-mutation");
test('clean Default ', function () {
var data = {
test: '',
};
var mutation = new obj_mutation_1.default({});
expect(mutation.parse(data)).toEqual({});
});
test('clean cleanValue ', function () {
var data = {
test: '',
test1: undefined,
};
var mutation = new obj_mutation_1.default({}, { cleanValue: '' });
expect(mutation.parse(data)).toEqual({ test1: undefined });
});
test('clean omit', function () {
var data = {
test: '123',
test1: '456',
};
var mutation = new obj_mutation_1.default({}, { omit: ['test1'] });
expect(mutation.parse(data)).toEqual({ test: '123' });
});
test('mutate', function () {
var data = {
test: 'haha',
};
var schema = {
test: {
mutate: {
test1: function (v) { return v + "hehe"; },
},
},
};
var mutation = new obj_mutation_1.default(schema);
expect(mutation.parse(data)).toEqual({ test1: 'hahahehe' });
});
test('create', function () {
var data = {
test1: 'haha',
test2: 'hehe',
};
var schema = {
test: {
create: function (obj) {
return obj.test1 + obj.test2;
},
},
};
var mutation = new obj_mutation_1.default(schema);
expect(mutation.parse(data)).toEqual({ test: 'hahahehe', test1: 'haha', test2: 'hehe' });
});
test('format', function () {
var data = {
test: 'haha',
};
var schema = {
test: {
format: function (v) { return v + "1"; },
},
};
var mutation = new obj_mutation_1.default(schema);
expect(mutation.parse(data)).toEqual({ test: 'haha1' });
});