Nuxt/packages/utils/test/serialize.test.js
2019-01-29 22:53:42 +03:30

62 lines
1.3 KiB
JavaScript

import { serializeFunction } from '../src/serialize'
describe('util: serialize', () => {
test('should serialize normal function', () => {
const obj = {
fn: function () {}
}
expect(serializeFunction(obj.fn)).toEqual('function () {}')
})
test('should serialize shorthand function', () => {
const obj = {
fn() {}
}
expect(serializeFunction(obj.fn)).toEqual('function() {}')
})
test('should serialize arrow function', () => {
const obj = {
fn: () => {}
}
expect(serializeFunction(obj.fn)).toEqual('() => {}')
})
test('should not replace custom scripts', () => {
const obj = {
fn() {
return 'function xyz(){};a=false?true:xyz();'
}
}
expect(serializeFunction(obj.fn)).toEqual(`function () {
return 'function xyz(){};a=false?true:xyz();';
}`)
})
test('should serialize internal function', () => {
const obj = {
fn(arg) {
if (arg) {
return {
title() {
return 'test'
}
}
}
}
}
expect(serializeFunction(obj.fn)).toEqual(`function(arg) {
if (arg) {
return {
title: function () {
return 'test';
}
};
}
}`)
})
})